tags:

views:

168

answers:

2

Hi,

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

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.

+1  A: 

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

Martin Hohenberg
A: 

This code will print out the details

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

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