XML 读取器是否应该忽略 XML 文件中的连续空格?
在我的工作中,我们有自己的 XML 类来构建 DOM,但我不确定应该如何处理连续的空格?
例如,
<some-text>
Hello World
</some-text>
当将其读入 DOM 时,文本节点应该包含 Hello 和 World 之间的连续空格还是将其减少到一个空格?
或者 XML 源应该这样写:
<some-text> Hello World </some-text>
或者如果不是 也许比 ?
At my work we have our own XML classes which build a DOM, but I'm not sure how consecutive whitespace should be handled?
e.g.
<some-text>
Hello World
</some-text>
When this is read into the DOM, should the text node include the consecutive whitespace inbetween Hello and World or just reduce it to one space?
Or should the XML source be written like this:
<some-text> Hello World </some-text>
or if not than perhaps ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不过,为了回答你的问题,我认为这很重要。 即使 HTML DOM 也将连续的空格视为重要的,只是它仅在视觉上呈现一个空格。 它在 DOM 中的显示方式和它在屏幕上的显示方式是完全不同的两件事。
To answer your question though, i would treat that as significant. Even the HTML DOM treats consecutive spaces as significant, it's just that it only visually renders one space. How it appears in the DOM and how it appears on your screen are two entirely different things.
编辑:标签内的空白被认为是重要的(我最初的想法就像 HTML 是错误的;首先谷歌,稍后回答问题!)参见 此说明
EDIT: whitespace within tags is considered significant (my initial thoughts on this being like HTML were wrong; google first, answer questions later!) see this explanation
在我看来,在这种情况下,将空格视为重要的空格似乎很自然。 我希望 DOM 节点的值等于我在标记中使用的值。
IMO it seems quite natural to treat whitespaces as significant in this case. I would expect DOM node's value to be equal to what I used in markup.
如果您“有我们自己的 XML 类”,而编写它们的人还不知道这个问题的答案,那么您可能还有很多很多尚未发现的问题。
If you "have our own XML classes," and whoever wrote them doesn't already know the answer to this question, you probably have many, many, many more problems that you just haven't discovered yet.
听到人们甚至没有查看 XML 规范就实现 XML 处理器,这有点令人不安。
来自 XML 1.0 规范,第 2.10 节空白处理”(强调我的):
It's a bit disconcerting to hear that people are out there implementing XML processors without even looking at the XML specifications.
From the XML 1.0 specification, section 2.10 White Space Handling" (emphasis mine):