Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order of Output of XML (Linq to XML)

Status
Not open for further replies.

planetbluau

Programmer
May 25, 2010
54
0
0
AU
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:

XML:
<sh:StandardBusinessDocument xmlns:sh="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"[/URL] xmlns:eanucc="urn:ean.ucc:2" xmlns:pay="urn:ean.ucc:pay:2" xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader[/URL] ../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:
XML:
<sh:StandardBusinessDocument xsi:schemaLocation="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader../Schemas/sbdh/StandardBusinessDocumentHeader.xsd[/URL] urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd" xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:pay="urn:ean.ucc:pay:2" xmlns:eanucc="urn:ean.ucc:2" xmlns:sh="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">[/URL]
</sh:StandardBusinessDocument>

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

Code:
 Dim sSchemaLocation As String = "[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader[/URL] ../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="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader../Schemas/sbdh/StandardBusinessDocumentHeader.xsd[/URL] urn:ean.ucc:2 ../Schemas/InvoiceProxy.xsd"
                 xmlns:sh="[URL unfurl="true"]http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"[/URL] xmlns:eanucc="urn:ean.ucc:2" xmlns:pay="urn:ean.ucc:pay:2" xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
                </sh:StandardBusinessDocument>

How can I change the order of the output?

Thanks,
Rodney
 
planetbluau said:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top