douwen3973 2017-11-23 14:36
浏览 50
已采纳

避免使用PHP在xml节点中删除标记元素

I want to parse a DocBook XML file with PHP. SimpleXMLElement cuts off some markup elements.

<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>

I use this code to parse my para elements:

$paras = $xml->xpath("//*[starts-with(local-name(), 'para')]");
foreach($paras as $para) {
   echo $para[0];
}

This cuts off my markup

<database>SUSPEND</database> and <quote>breaks</quote>

resulting in

The command the atomicity of the block in which it is located.

But what I need is:

The <database>SUSPEND</database> command <quote>breaks</quote> the atomicity of the block in which it is located.

So how can I get the whole node including its elements as string?

  • 写回答

1条回答 默认 最新

  • duanqie5741 2017-11-23 14:56
    关注

    Just use asXML method to get tree with root at element found

    foreach($paras as $para) {
       echo $para->asXML();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播