INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Order of Output of XML (Linq to XML)

Order of Output of XML (Linq to XML)

(OP)
Hi,

I know that this is possibly not a real issue, however I am trying to write a vb.NET application using LINQ to XML and match an existing applications (for which I don't have the source code) output.

The XML output I am trying to match is:

CODE --> XML

<sh:StandardBusinessDocument xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:eanucc="urn:ean.ucc:2" xmlns:pay="urn:ean.ucc:pay:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd">
</sh:StandardBusinessDocument> 

However when I use my code, regardless of the order of the code entries I get:

CODE --> XML

<sh:StandardBusinessDocument xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pay="urn:ean.ucc:pay:2" xmlns:eanucc="urn:ean.ucc:2" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
</sh:StandardBusinessDocument> 

Here is a snippet from my code that produces this part of the XML:

CODE --> vb.NET

Dim sSchemaLocation As String = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd"
        Dim newPO As XDocument = _
             <?xml version="1.0" encoding="UTF-8"?>
             <sh:StandardBusinessDocument xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader../Schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd"
                 xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:eanucc="urn:ean.ucc:2" xmlns:pay="urn:ean.ucc:pay:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                </sh:StandardBusinessDocument> 

How can I change the order of the output?

Thanks,
Rodney

RE: Order of Output of XML (Linq to XML)

Quote (planetbluau)

I know that this is possibly not a real issue,

It is only an issue if something is broken.

The two results are identical as far as XML is concerned. If the application receiving the XML document is complaining, then its XML parser is broken, and you will have to resort to other methods to control more strictly the output of the namespace declarations. I observe that the XML serialization seems to be reversing the order from the declaration in your source, so perhaps you simply need to reverse the order of the namespace declarations in your source to achieve the desired output.

Since one of the areas that LINQ claims to simplify is namespaces, I would guess that you don't have a lot of control over namespaces while using LINQ. You might have more control if you use XML DOM instead.

But to reiterate: The XML output you are getting is by definition identical to that which you desire.

Tom Morrison
Hill Country Software

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close