【发布时间】:2015-09-18 18:42:03
【问题描述】:
我正在尝试搜索我创建的 XML 文档,但我似乎无法让它正常工作。这是我的 XML 文档...
<?xml version="1.0" encoding="UTF-8"?>
<states>
<repstate location="AL">
<compName>Test Company</compName>
<name>Chris Brown</name>
<address>123 Main St</address>
<city>Anytown</city>
<state>CT</state>
<phone>203-123-4567</phone>
<fax>203-456-7890</fax>
<email>info@email.com</email>
<website>www.testing.com</website>
<serviceArea>All of Alabama</serviceArea>
</repstate>
<repstate location="AK">
<compName>Test Company</compName>
<name>Chris Brown</name>
<address>123 Main St</address>
<city>Anytown</city>
<state>CT</state>
<phone>203-123-4567</phone>
<fax>203-456-7890</fax>
<email>info@email.com</email>
<website>www.testing.com</website>
<serviceArea>All of Alabama</serviceArea>
</repstate>
</states>
这是我要开始工作的代码 sn-p...
<?php
$xml = simplexml_load_file('../../usa.xml');
$found = $xml->xpath("//@location='AK'");
echo $found->state;
?>
它似乎无法正常工作。
我正在尝试在该节点中加载信息。所以所有的compName、姓名、地址、城市、州、电话、传真、电子邮件、网站和服务区。我认为让“状态”工作很容易,但似乎没有任何输出。我做错了什么?
【问题讨论】: