views:

29

answers:

1
XmlSerializer serializer = new XmlSerializer(typeof(IxComment));
System.IO.StringWriter aStream = new System.IO.StringWriter();
serializer.Serialize(aStream,Comments);
commentsString = aStream.ToString();

Here the commentsString has the the following element in it

<IxComment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;

Is there any possibility to interchange the xsi and xsd attribute and get the element as shown below

<IxComment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

Will this cause any other issue?

EDIT: Why do i need to do this?

We are migrating an existing application from 1.1 to 3.0 and in the code there is a if loop

int iStartTagIndex = strXMLString.IndexOf("<IxComment xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"&gt;");

that check for the index of the IxComment. Here the o/p of the serializer and the condition differ in the position of xsd and xsi. So i am trying to know whether we can instruct the serializer to provided the o/p as required.

I have another question here as this was an existing application does the serializer O/P differs with versions?

+1  A: 

I hope there's no way to affect the order of things that should not matter to any piece of code that understands XML. Any piece of code that has problems with the order of namespace declarations is badly broken and must be fixed, period.


After seeing your edit, I'm even more adamant: fix your broken code. Your code should never have performed string processing on XML. You should simply fix your code and not try to fix the XML standard, which dictates that the order of namespace declarations is not relevant.

John Saunders
Will the O/P of the XmlSerializer differs with versions? As i noticed the current IxComment element differs with one already existing in the DB
Sri Kumar
+1 - My comment above already assumed that something like that is the case. OP: Fix the assumption. XML attributes are unordered. If your legacy code relies on a specific order, it's just plain wrong. Try to fix the real issue, without creating a workaround.
Benjamin Podszun