gpt4 book ai didi

xml - XML 阅读器是否应该忽略 XML 文件中的连续空格?

转载 作者:数据小太阳 更新时间:2023-10-29 02:48:23 29 4
gpt4 key购买 nike

在我的工作中,我们有自己的 XML 类来构建 DOM,但我不确定应该如何处理连续的空格?

例如

<some-text>
Hello World
</some-text>

当它被读入 DOM 时,文本节点应该包含 Hello 和 World 之间的连续空白还是只将其减少到一个空格?

或者XML源应该这样写:

<some-text>Hello &nbsp;&nbsp;&nbsp;&nbsp;World</some-text>

或者如果不是  比也许 ?

最佳答案

听说人们甚至不看 XML 规范就实现 XML 处理器,这有点令人不安。

来自XML 1.0 specification, section 2.10 White Space Handling" (强调我的):

In editing XML documents, it is often convenient to use "white space" (spaces, tabs, and blank lines) to set apart the markup for greater readability. Such white space is typically not intended for inclusion in the delivered version of the document. On the other hand, "significant" white space that should be preserved in the delivered version is common, for example in poetry and source code.

An XML processor MUST always pass all characters in a document that are not markup through to the application. A validating XML processor MUST also inform the application which of these characters constitute white space appearing in element content.

A special attribute named xml:space may be attached to an element to signal an intention that in that element, white space should be preserved by applications. In valid documents, this attribute, like any other, MUST be declared if it is used. When declared, it MUST be given as an enumerated type whose values are one or both of "default" and "preserve". For example: ...

关于xml - XML 阅读器是否应该忽略 XML 文件中的连续空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/449532/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com