解析php中的xml文件

时间:2012-05-30 18:35:38

标签: php xml

如何在php中解析这种类型的文件 我尝试过使用

<?php
$xml ="office.xml";

// get first book title
$title=$xml->featureMember->AA_OFFICE;
// show title
echo $title;
echo '<br/>';
?>

如果我使用gml:featuremember而不是featuremember,我的语法错误 如果我使用featuremember iam)注意:尝试获取非对象的属性

<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<gml:featureMember>
<kgp:AA_OFFICE fid="AA_OFFICE.1">
<kgp:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#32645">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">643630.3815,2498825.0741</gml:coordinates>
</gml:Point>
</kgp:the_geom>
<kgp:Name>MANMARK EXPORT PVT LTD</kgp:Name>
<kgp:Type/>
<kgp:Plot_No>55</kgp:Plot_No>
<kgp:Block_Name>AA</kgp:Block_Name>
</kgp:AA_OFFICE>
</gml:featureMember>

2 个答案:

答案 0 :(得分:1)

您正在尝试将字符串用作对象。您必须首先创建某种形式的XML Parsing对象。例如,

$xmlDoc = new DOMDocument();
$xmlDoc->load("office.xml");

More information

$xml = simplexml_load_file("office.xml");

More information

答案 1 :(得分:0)

尝试调试你的xml

libxml_use_internal_errors(true);
$xml = simplexml_load_file("office.xml");
var_dump(libxml_get_errors());
相关问题