开发者

nested xml document in Simplexml document

I have a problem when using simplexml to read a xml document that I am getting back from a webservice call.

Reading the data is fine however one node called UserArea contains a nested XMLdocument which contains namespaces.

From this question on SO I've looked at how to deal with child nodes. However when I call the node that has this nested XML in it I get null back.

The data looks like this:

<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:Exp开发者_Python百科erience>

    <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>

I am out of ideas because the code:

foreach($myObject->UserArea->children as $userAreaXML){

   foreach($userAreaXML->ExperianceSummary as $summary){
      echo $summary->Detail;
   } 
}

just doesn't work.


You might want to read http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ .. Couldn't be explained much clearer.


This code will print out the details

$experiences = $myObject->ExperienceSummary->Experience;

foreach($experiences as $experience) {
 echo $experience->Detail . "<br>";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜