【问题标题】:Parsing XML in PHP with XMLReader - mixed content element - where'd my text go?使用 XMLReader 在 PHP 中解析 XML - 混合内容元素 - 我的文本去哪儿了?
【发布时间】:2011-03-13 00:02:24
【问题描述】:

我无法解析一段纯文本;即使使用打印语句遍历所有节点,它们都不包含我在 XML 文件中编写的文本。

这是来自 DTD 的元​​素规范:

<!ELEMENT question (#PCDATA | choice)*>

这是我正在使用的数据:

<question id="porridge" name="porridge" type="multiple">
 What is 1 + 2?
 <choice id="twelve" value="twelve">12</choice>
 <choice id="three" value="three" correct="true">3</choice>
 <choice id="banana" value="banana">Banana!</choice>
</question>

中的第一个节点是 XMLReader::TEXT 类型,但根据 readOuterXML(),它是空的。我怎样才能了解“什么是 1 + 2?”

【问题讨论】:

    标签: php xml xmlreader


    【解决方案1】:

    readOuterXML() 移动当前节点并且在所有情况下都不会返回节点的实际内容。我的测试循环破坏了其余的解析。

    【讨论】:

      猜你喜欢
      • 2021-09-19
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 2016-10-15
      • 2018-06-12
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多