0

I have a few XML files in a format like this

...
<section>
  <header>Headline</header>
  <par>Some text <em>here</em> and more text.</par>
</section>
....

At first I used the PHP pull-parser XMLReader which just walked through the file, and I could respond to whatever node type the reader would run across. This all worked quite well, but the code felt bloated and there was some context information that I needed which required me to drag additional state around. For example, a <header> tag can be a child to a section or subsection tag.

So I switched to SimpleXML because it would represent the XML document as a recursive data structure, and provide me with XPath functionality. No more state (as I can query the context for, eg header tags) and the code is much more compact.

However... How do I access the "Some text " and " and more text." child nodes of the <par> tag? Is that possible, or can I not parse a soup with SimpleXML? Should I better use a DOMDocument implementation, and if so, which one? Where's the difference to SimpleXML?

4

1 回答 1

0

我上面描述的问题与这个问题中的问题非常相似:Getting the text section of a node using php Simple XML

简短回答:SimpleXML 无法处理文本节点,请改用 DOMDocument 实例。参考线程中的更多详细信息和解决方案。

于 2013-06-25T11:42:51.003 回答