使用simplexml读取我从Web服务调用中返回的xml文档时遇到问题。
读取数据很好但是一个名为 UserArea 的节点包含一个包含名称空间的嵌套XML文档。
从this question开始我已经看过如何处理子节点了。但是,当我调用其中包含此嵌套XML的节点时,我将返回null。
数据如下所示:
<UserArea>
<rm:EngineVersion>4.2.0.62</rm:EngineVersion>
<rm:DocumentFormat>305</rm:DocumentFormat>
<rm:Industry>AUT</rm:Industry>
<rm:Department>GEN</rm:Department>
<rm:HighestDegree year="2004" major="COMPUTER PROGRAMMING">BACHELORS</rm:HighestDegree>
<rm:ExperienceSummary>
<rm:Experience>
<rm:ExperienceKind>Summary</rm:ExperienceKind>
<rm:Years>11</rm:Years>
<rm:Detail>A total of 11 years of work experience.</rm:Detail>
</rm:Experience>
<rm:Experience>
<rm:ExperienceKind>HighestIndustry</rm:ExperienceKind>
<rm:Years>5</rm:Years>
<rm:Industry>AUT</rm:Industry>
<rm:Detail>Highest industry-related experience is 5 years in automotive </rm:Detail>
</rm:Experience>
</rm:ExperienceSummary>
</UserArea>
我没有想法,因为代码:
foreach($myObject->UserArea->children as $userAreaXML){
foreach($userAreaXML->ExperianceSummary as $summary){
echo $summary->Detail;
}
}
只是不起作用。
答案 0 :(得分:1)
您可能需要阅读http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ ..无法更清楚地解释。
答案 1 :(得分:0)
此代码将打印出详细信息
$experiences = $myObject->ExperienceSummary->Experience;
foreach($experiences as $experience) {
echo $experience->Detail . "<br>";
}