【发布时间】:2016-06-24 08:50:10
【问题描述】:
我有一个 symfony xml-config,需要解析它。
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="abcxyz" type="collection">
<parameter key="abc" type="collection">
<parameter key="a" type="string">a</parameter>
<parameter key="b" type="string">b</parameter>
<parameter key="c" type="constant">\My\Bundle\Type::TYPE_ABC</parameter>
</parameter>
<parameter key="xyz" type="collection">
<parameter key="x" type="string">x</parameter>
<parameter key="y" type="string">y</parameter>
<parameter key="z" type="constant">\My\Bundle\Type::TYPE_XYZ</parameter>
</parameter>
</parameter>
</parameters>
</container>
我需要获取值“abc”和“xyz”。 我试着用
$simpleXml = simplexml_load_string(file_get_contents(__DIR__ . '/myConfig.xml');
var_dump($simpleXml->xpath('//parameters/parameter/parameter/@key'));
但是结果是空的……
【问题讨论】:
标签: php symfony xpath xml-parsing