【发布时间】:2017-02-09 15:17:40
【问题描述】:
你好我想在xml文件属性值中搜索,如果找到(结果只能是1)用其他属性读取整行,问题是我在xml中有点新鲜,所以不要评判我我试图查找信息,但只有节点搜索方法。
<?php
$ged =1;
$xmlStr = file_get_contents("data_map/data_output.xml");
$xml = new SimpleXMLElement($xmlStr);
$res = $xml->xpath("markers/marker/id='. $ged .'");
echo $res;
?>
我的xml文件在属性中,但我的php代码只返回这个错误:
注意:第 7 行 D:\xampp\htdocs\test\test.php 中的数组到字符串转换 数组
<?xml version="1.0" encoding="utf-8"?>
<markers>
<marker id="1" name="Love.Fish" address="580 Darling Street, Rozelle, NSW" lat="-33.861034" lng="151.171936" type="restaurant" duty="very tall people"/>
<marker id="2" name="house party" address="Information Centre" lat="55.499996" lng="25.608803" type="restaurant" duty="very kind people."/>
</markers>
我认为是我的查询不正确,而且在我得到正确的行之后,如何读取它并将每个属性放入不同的变量中?
【问题讨论】: