我想用 PHP 解析一个 DocBook XML 文件。SimpleXMLElement 切断了一些标记元素。
<section>
<title>SUSPEND</title>
<para>The <database>SUSPEND</database> command <quote>breaks</quote> the atomicity of the block in which it is located.</para>
<para>...</para>
</section>
我使用这段代码来解析我的 para 元素:
$paras = $xml->xpath("//*[starts-with(local-name(), 'para')]");
foreach($paras as $para) {
echo $para[0];
}
这切断了我的标记
<database>SUSPEND</database> and <quote>breaks</quote>
导致
The command the atomicity of the block in which it is located.
但我需要的是:
The <database>SUSPEND</database> command <quote>breaks</quote> the atomicity of the block in which it is located.
那么我怎样才能得到整个节点,包括它的元素作为字符串呢?