c# - 在 XmlSerializer 的输出中交换 xsd 和 xsi

标签 c# xsd xmlserializer 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 是否因版本而异?

最佳答案

我希望没有办法影响那些对任何理解 XML 的代码都无关紧要的事情的顺序。任何与 namespace 声明顺序有问题的代码都严重损坏,必须修复,句号。


看到您的修改后,我更加坚定:修复您损坏的代码。您的代码不应该对 XML 执行字符串处理。您应该简单地修复您的代码,而不是尝试修复 XML 标准,该标准规定命名空间声明的顺序不相关。

关于c# - 在 XmlSerializer 的输出中交换 xsd 和 xsi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2577895/

相关文章:

c# - 这个委托(delegate)的使用是好是坏?

c# - 为什么不是 0==0?

c# - 为什么访问匿名管道时会收到 “Invalid pipe handle”?

java - JAXB : how to read the xsi:type value when unmarshalling

C# System.Xml.Serialization - 仅使用 <a></a> 而从不使用 <a/>

c# - 从模板类转换

java.lang.IllegalArgumentException : No SchemaFactory that implements the schema language specified by: http://www. w3.org/XML/XMLSchema/v1.1

java - 关于 XML 模式的 Json 到 XML 到 Json

java - 从android发送序列化数据到java

java - 在 C# 中序列化 Java 对象和反序列化