如何在PHP中使用Xpath解析XML的单个子节点中的子子多个节点

时间:2018-06-21 06:56:44

标签: php xml parsing xpath

朋友,我无法在下面的Give XML中从子节点打印子子项,请帮助我解决此问题。

XML:

<section index="2.2.4" title="Recommendation" ref="RECOMMENDATION">
          <text>DWS strongly recommends that all authentication credentials should be configured with a strong password.</text>
          <text>DWS recommends that:</text>
          <list type="bullet">
            <listitem>passwords should be at least eight characters in length;</listitem>
            <listitem>characters in the password should not be repeated more than five times;</listitem>
            <listitem>passwords should include both upper case and lower case characters;</listitem>
            <listitem>passwords should include numbers;</listitem>
            <listitem>passwords should include punctuation characters;</listitem>
            <listitem>passwords should not include the username;</listitem>
            <listitem>passwords should not include a device's name, make or model;</listitem>
            <listitem>passwords should not be based on dictionary words.</listitem>
          </list>
          <text>Notes for Cisco Catalyst Switch devices:</text>
          <text>The following commands can be used on Cisco Catalyst Switch devices to set the enable password, create a local user with a password and to delete a local user:<code><command>enable secret <cmduser>password</cmduser></command>
<command>username <cmduser>user</cmduser> secret <cmduser>password</cmduser></command>
<command>no username <cmduser>user</cmduser></command>
</code></text>
        </section>

代码:

<?php
$xml = simplexml_load_file("toshibaconfig2.xml");

$report = $xml->xpath("//section [@index = '2.2.4'] //code");

//foreach ($report as $reports)

print_r($report);

我需要按以下顺序解析<code></code>

enable secret password
username user secret password
no username user

请帮助我解决此问题。

0 个答案:

没有答案