php - 如何使用Php中的Xpath解析XML中单个子节点中的子多个节点
问题描述
朋友,我无法从下面给出的 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
请帮我解决这个问题。
解决方案
推荐阅读
- r - 适用于 data.frame 选择值> 0 与 R
- angular6 - 在 Angular6 应用程序中,应用程序组件未加载(占用)
- javascript - 在 NodeJS 中,如何在不同的文件中使用相同的对象?
- regex - 积极的后视/前瞻 RegEx VBA
- php - 从 DATABASE 恢复用户的角色
- java - Java 8:以非静态方式对静态方法的方法引用
- javascript - 发生异常时如何使 Karma 报告测试失败?
- python - 使用 Python 请求 (POST) + API 的困难
- javascript - 如何使用 Javascript 对这个 JSON 进行排序?
- kubernetes - Kubernetes:必须通信的多个容器+暴露的nodePort