互换 XmlSerializer 输出中的 xsd 和 xsi
XmlSerializer serializer = new XmlSerializer(typeof(IxComment));
System.IO.StringWriter aStream = new System.IO.StringWriter();
serializer.Serialize(aStream,Comments);
commentsString = aStream.ToString();
这里的 commentsString 中有以下元素
<IxComment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
是否有可能互换 xsi 和 xsd 属性并获取如下所示的元素
<IxComment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
这会导致任何其他问题吗?
编辑:为什么我需要这样做?
我们正在将现有应用程序从 1.1 迁移到 3.0,代码中有一个 if 循环
int iStartTagIndex = strXMLString.IndexOf("<IxComment xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
用于检查 IxComment 的索引。 这里串行器的 o/p 和条件在 xsd 和 xsi 的位置上有所不同。所以我想知道我们是否可以指示序列化器根据需要提供o/p。
我这里还有另一个问题,因为这是一个现有的应用程序,序列化器 O/P 是否因版本而异?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望没有办法影响对任何理解 XML 的代码来说无关紧要的事情的顺序。任何与命名空间声明顺序有问题的代码都被严重破坏,必须修复。
看到您的编辑后,我更加坚定:修复您损坏的代码。您的代码不应该对 XML 执行字符串处理。您应该简单地修复代码,而不是尝试修复 XML 标准,该标准规定名称空间声明的顺序不相关。
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.