Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在XmlSerializer的输出中交换xsd和xsi_C#_Xsd_Xmlserializer_Xsi - Fatal编程技术网

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

C# 在XmlSerializer的输出中交换xsd和xsi,c#,xsd,xmlserializer,xsi,C#,Xsd,Xmlserializer,Xsi,这里,commentsString中包含以下元素 XmlSerializer serializer = new XmlSerializer(typeof(IxComment)); System.IO.StringWriter aStream = new System.IO.StringWriter(); serializer.Serialize(aStream,Comments); commentsString = aStream.ToString(); 是否有可能交换xsi和xsd属性并

这里,commentsString中包含以下元素

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

是否有可能交换xsi和xsd属性并获得如下所示的元素

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

这会导致其他问题吗

编辑:我为什么需要这样做

我们正在将现有应用程序从1.1迁移到3.0,代码中有一个if循环

<IxComment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
int-iStartTagIndex=strXMLString.IndexOf(“”);
检查IxComment的索引。 这里序列化程序的o/p和条件在xsd和xsi的位置不同。因此,我试图知道我们是否可以指示序列化程序根据需要提供o/p


这里我还有一个问题,因为这是一个现有的应用程序,序列化程序O/p是否与版本不同?

我希望没有办法影响对任何理解XML的代码都不重要的事情的顺序。任何与名称空间声明顺序有问题的代码都会被严重破坏,并且必须修复,句号为



看到你的编辑后,我更加坚定:修复你的坏代码。您的代码不应该对XML执行字符串处理。您应该只修复代码,而不尝试修复XML标准,因为XML标准规定命名空间声明的顺序不相关。

我不知道是否或如何修复,但我想问一下为什么?您是否正在为无法处理XML的使用者创建XML(使用字符串拆分或-上帝禁止-正则表达式替代)?XmlSerializer的O/P是否会因版本而异?正如我注意到的,当前的IxComment元素与DB+1中已经存在的元素不同——我上面的注释已经假设了类似的情况。OP:修正假设。XML属性是无序的。如果您的遗留代码依赖于特定的顺序,那么这完全是错误的。尝试修复真正的问题,而不创建解决方法。例外当然是版本控制,它在我切换机器时识别我的repo中的每个xml文件都已更改:)在寻找此问题的答案时遇到了您的答案…@stod这不是例外。版本控制将它们作为文本文件处理,而不是XML。
int iStartTagIndex = strXMLString.IndexOf("<IxComment xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");