为什么w3c.dom.Element按照字母顺序设置属性?

发布于 2024-10-04 02:12:21 字数 98 浏览 0 评论 0原文

我正在使用 org.w3c.dom.Element 将元素添加到 xml 文件。这里的问题是当设置属性时它会根据字母顺序添加而不是添加顺序。如何忽略这种行为?

谢谢。

I am using org.w3c.dom.Element for adding elements to a xml file. Problem here is when setting attributes it adding according to the alphabetic order instead of adding order. How to ignore that behavior?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

醉生梦死 2024-10-11 02:12:21

如果您指的是 XML 文档的结果序列化形式的顺序,则属性的顺序并不重要。来自规范

请注意,开始标记或空元素标记中属性规范的顺序并不重要。

If you mean the order in a resulting serialized form of the XML document, the order of attributes is not significant. From the spec:

Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.

幽蝶幻影 2024-10-11 02:12:21

正如 @TJ Crowder 所说,序列化 XML 文档中的属性顺序并不重要。 (属性的顺序不是 XML 信息集的一部分。)

这意味着 DOM、XML 解析器和 XML 序列化器的实现没有义务允许您为 DOM 中的属性指定特定的顺序,或者在序列化、解析或转换 XML 文档时保留明显的顺序。

如果您有一些依赖于 XML 属性顺序的应用程序(或测试用例),那么它就会被破坏并且应该被修复。

As @T.J. Crowder says, the order of attributes in a serialized XML document is not significant. (And the order of attributes is not part of the XML infoset.)

What this means is that implementations of the DOM, XML parsers and XML serializers are under no obligation to allow to let you specify a particular ordering for attributes in a DOM, or to preserve the apparent ordering when serializing, parsing or transforming an XML document.

If you have some application (or test case) that depends on the order of XML attributes, it is broken and should be fixed.

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