Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中读取xml节点_Php_Xml - Fatal编程技术网

在php中读取xml节点

在php中读取xml节点,php,xml,Php,Xml,我试图从php中的xml中读取一些特定的子节点,我想显示这些子节点,但无法显示节点值 <nns2:ApiDirectory xmlns:ns2="https://sourceurl.com/api> <api:groups> <entry> <key>Affiliate</key> <value> <apilisti

我试图从php中的xml中读取一些特定的子节点,我想显示这些子节点,但无法显示节点值

<nns2:ApiDirectory xmlns:ns2="https://sourceurl.com/api>
   <api:groups>
        <entry> 
            <key>Affiliate</key>
            <value>
                <apilisting>
                    <entry>
                        <key>value</key>
                            <value>
                                <get>https://url1.com</get>
                            </value>
                    </entry>
                </apilisting>
            </value>
        </entry>
    </api>
</ns2>

您的代码中有一个输入错误

echo $xml->ns2->api:groups->entry->value->apilisting-entry->value->{get};
应该是:

echo $xml->ns2->api:groups->entry->value->apilisting->entry->value->{get};
请注意
->
之后的
列表


请注意:xml示例中的组名称空间。

为了让PHP理解,您必须对如下对象强制进行类型转换:

$array = (array) $xml->ns2->api:groups->entry->value->apilisting->entry->value->get; 

print_r($array);
输出:

Array ([0] => 'https://url1.com')

共享您当前的代码,以便我们查看错误所在的位置,以及您希望获取和存储的节点。好的,我正在发布,先生…请立即检查,先生…很抱歉输入错误,但我仍然无法打印所需的节点。这是因为节点处理中的冒号吗???
应该是
。此外,还必须定义xml文档中的名称空间。在php语句中尝试将冒号添加到节点时出现语法错误,我正在使用curl从api读取此xml,因此xml具有名称空间。。
Array ([0] => 'https://url1.com')