XML:什么处理规则适用于与标签交织的值?
我已经开始研究一个简单的 XML 拉解析器,并且我刚刚开始思考 XML 中关于某些字符/序列、可忽略的空格等的正确语法是什么(谢谢,http://www.w3schools.com/xml/xml_elements.asp),我意识到我仍然不知道不知道可以勾勒出以下情况(Validome 发现很好) -形成非常多;请注意,我只想使用 xml 文件进行数据存储,不需要实体、DTD 或模式):
<bookstore>
<book id="1">
<author>Kurt Vonnegut Jr.</author>
<title>Slapstick</title>
</book>
We drop a pie here.
<book id="2">Who cares anyway?
<author>Stephen King</author>
<title>The Green Mile</title>
</book>
And another one here.
<book id="3">
<author>Next one</author>
<title>This time with its own title</title>
</book>
</bookstore>
“我们在这里放一块馅饼。” 和“这里还有另一个。” 是“bookstore”元素的值。 “谁在乎呢?” 是与第二个“book”元素相关的值。
如果有的话,这些是如何处理的? 威尔“我们在这里放一块馅饼。” 和“这里还有一个。” 被连接起来形成“bookstore”元素的一个值,或者它们被单独处理,存储在某处,影响它们所属元素的解析结果,或者......?
I have started working on a simple XML pull-parser, and as I've just defuzzed my mind on what is the correct syntax in XML with regards to certain characters/sequences, ignorable whitespace and such (thank you, http://www.w3schools.com/xml/xml_elements.asp), I realized that I still don't know squat about what can be sketched up as the following case (which Validome finds well-formed very much; note that I only want to use xml files for data storage, no entities, DTD or Schemas needed):
<bookstore>
<book id="1">
<author>Kurt Vonnegut Jr.</author>
<title>Slapstick</title>
</book>
We drop a pie here.
<book id="2">Who cares anyway?
<author>Stephen King</author>
<title>The Green Mile</title>
</book>
And another one here.
<book id="3">
<author>Next one</author>
<title>This time with its own title</title>
</book>
</bookstore>
"We drop a pie here." and "And another one here." are values of the 'bookstore' element.
"Who cares anyway?" is a value related to the second 'book' element.
How are these processed, if at all? Will "We drop a pie here." and "Another one here." be concatenated to form one value for the 'bookstore' element, or are they treated separately, stored somewhere, affecting the outcome of the parsing of the element they belong to, or...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是使用一些符合标准的解析器解析它并转储输出。
Easiest way to go is to parse it with a few standards-compliant parsers and dump the output.