互换 XmlSerializer 输出中的 xsd 和 xsi

发布于 2024-08-28 05:29:57 字数 1033 浏览 12 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2024-09-04 05:29:57

我希望没有办法影响对任何理解 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文