开发者

Interchange xsd and xsi in the output of XmlSerializer

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">

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\">");

that check fo开发者_开发技巧r 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜