views:

238

answers:

1

A related question to one I asked earlier...

Just checking on something: Should the order of the xmlns, xmlns:xsi and xsi:schemaLocation attributes in an XML file matter?

I'm finding that it does - at least when using XML Notepad 2007 to view the XML file. For example (assuming that my XML file is legal according to my schema) this gives no errors (Example 1):

<myroot 
    xmlns="http://www.someurl.com/ns/myroot" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd"&gt;

   <sometag>somecontent</sometag>

</myroot>

but this one does (Example 2):

<myroot 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd"
    xmlns="http://www.someurl.com/ns/myroot"&gt; 

   <sometag>somecontent</sometag>

</myroot>

(the error being that 'sometag' is an illegal entry according to the schema).

My problem is that if I use the code from my other question to generate my namespace and schema attributes then I get the XML attributes output in the Example 2 order...

Does the xmlns attribute always have to be first in the attribute list?

+1  A: 

Ah - I've spotted my problem....

The XML I'm actually working on is fiendishly complicated and I hadn't noticed that I'd inserted an xmlns="" in all my child nodes. Once I remove that the problem goes away and the ordering of namespace attributes makes no difference - which is what I expected...

SAL
Id you ever manage to sort out the ordering anyway?
Dan