I am having an issue wrapping my head around the SimpleXML syntax.
I am trying to echo a few pieces of info I pull out of a larger xml document based on a predefined value DELN:
$mytimes= simplexml_load_file('http://www.bart.gov/dev/eta/bart_eta.xml');
$freemont = $mytimes->station->abbr[DELN]->eta->destination[freemont]->estimate;
$millbrae = $mytimes->station->abbr[DELN]->eta->destination[millbrae]->estimate;
$richmond = $mytimes->station->abbr[DELN]->eta->destination[richmond]->estimate;
My XML:
<station>
<name>El Cerrito del Norte</name>
<abbr>DELN</abbr>
<date>11/30/2012</date>
<time>07:41:02 AM PST</time>
<eta>
<destination>Fremont</destination>
<estimate>14 min, 29 min, 44 min</estimate>
</eta>
<eta>
<destination>Millbrae</destination>
<estimate>6 min, 21 min, 36 min</estimate>
</eta>
<eta>
<destination>Richmond</destination>
<estimate>4 min, 10 min, 17 min</estimate>
</eta>
</station>
Let me know if I need to provide more info. Thanks.
First - I suppose you're not defining DELN constant, probably you should use a string ('DELN'). Same with freemont, millbrae and richmont. The problem is not only SimpleXML syntax, basically its misunderstanding of XML structure that you want to read (abbr is not in straight path with eta, same with destination and estimate). Anyway - xpath will be your friend here:
$fremont = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Fremont\']');
$millbrae = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Millbrae\']');
$richmond = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Richmond\']');
then you can do:
foreach ($fremont as $value) echo $value;
or just
if (count($fremont) > 0) echo $fremont[0];
Related
How can parse XML with this structure :
<sdk:sdk-repository xmlns:sdk="http://schemas.android.com/sdk/android/repository/7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
Generated on Thu Oct 22 10:16:34 PDT 2009 using eclair-sdk 17704: Platform. Addon. Tools. Doc.
-->
<sdk:platform>
<sdk:version>2.0</sdk:version>
<sdk:api-level>5</sdk:api-level>
<sdk:codename/>
<sdk:revision>01</sdk:revision>
<sdk:min-tools-rev>
<sdk:major>3</sdk:major>
</sdk:min-tools-rev>
<sdk:description>Android SDK Platform 2.0, revision 1</sdk:description>
<sdk:desc-url>http://developer.android.com/sdk/android-2.0.html</sdk:desc-url>
<sdk:obsolete/>
<sdk:archives>
<sdk:archive arch="any" os="linux">
<sdk:size>75095268</sdk:size>
<sdk:checksum type="sha1">be9be6a99ca32875c96ec7f91160ca9fce7e3c7d</sdk:checksum>
<sdk:url>android-2.0_r01-linux.zip</sdk:url>
</sdk:archive>
<sdk:archive arch="any" os="macosx">
<sdk:size>74956356</sdk:size>
<sdk:checksum type="sha1">2a866d0870dbba18e0503cd41e5fae988a21b314</sdk:checksum>
<sdk:url>android-2.0_r01-macosx.zip</sdk:url>
</sdk:archive>
<sdk:archive arch="any" os="windows">
<sdk:size>76288040</sdk:size>
<sdk:checksum type="sha1">aeb623217ff88b87216d6eb7dbc846ed53f68f57</sdk:checksum>
<sdk:url>android-2.0_r01-windows.zip</sdk:url>
</sdk:archive>
</sdk:archives>
<sdk:layoutlib>
<sdk:api>4</sdk:api>
</sdk:layoutlib>
<sdk:uses-license ref="android-sdk-license"/>
</sdk:platform>
...
how can get Version? and size?
and even get Generated date ?( on Thu Oct 22 10:16:34 PDT 2009 using eclair-sdk 17704: Platform. Addon. Tools. Doc. ) for each SDK Platform(sdk:platform)
very very TNX
Parsing the XML and parsing the comment in the file are two completely separate things.
Regarding the XML itself, you can use PHP's SimpleXml to parse it, but you'll have to remember to specify the namespace when accessing the children-elements.
We know we want namespaces, and we know which one we want, because each node that we're interested in is prefixed with something:. For example:
<sdk:version>2.0</sdk:version>
So, in this case, we are interested in the sdk namespace. You can find where the namespaces are defined in the top-most declaration node:
<sdk:sdk-repository xmlns:sdk="http://schemas.android.com/sdk/android/repository/7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
This declares the sdk namespace to be http://schemas.android.com/sdk/android/repository/7. The 7 is a version number, so keep this in mind if you ever need to update to use different SDKs.
A small example of parsing the XML, using your sample XML, would be:
// load the file and create the XML element
$feed = file_get_contents("repository.xml");
$xml = new SimpleXmlElement($feed);
// define the namespace you need to use (we want xmlns:sdk)
$sdk = $xml->children("http://schemas.android.com/sdk/android/repository/7");
// get the "platform" root element and start using it's nodes
$platform = $sdk->platform;
echo 'Version: ' . $platform->version . "<br />";
echo 'Description: ' . $platform->description . "<br />";
foreach ($platform->archives->archive as $archive) {
echo 'Archive: ' . $archive->url . ", size: " . $archive->size . "<br />";
}
To match the Generated on ... line, you'll either need to use substring parsing or build a regex that can parse it. I'm opting for the latter option to save lines-of-code, but it's really up to you how you'd prefer to go about it.
If you wanted to use a regex, and this is very-specific to the output in your sample XML so you may need to adjust it to be more dynamic, you can use PHP's preg_match and a very verbose pattern:
$pattern = '/<!--[\r\n\s]*Generated on (.*) using eclair-sdk 17704: Platform\. Addon\. Tools\. Doc\.[\r\n\s]*-->/';
$comments = array();
preg_match($pattern, $feed, $comments);
echo $comments[1];
Output:
Thu Oct 22 10:16:34 PDT 2009
I have the following XML file
<study>
<participant name="Jone" gender="male" nationality="Canadian" job="web developer" country="Canada" years="2"/>
<scenario_1>
<s1_first name="drieseng">Scenario 1 first developer</s1_first>
<s1_second name="Scott Hernandez">Scenario 1 2nd developer</s1_second>
<s1_third name="Ryan Boggs">Scenario 1 3rd developer</s1_third>
<s1_forth name="Ian MacLean">Scenario 1 4th developer</s1_forth>
<s1_fifth name="Michael C. Two">Scenario 1 5th developer</s1_fifth>
</scenario_1>
<scenario_2>
<s2_first name="Charles Chan">Scenario 2 1st developer</s2_first>
<s2_second name="Charles Chan">Scenario 2 2nd developer</s2_second>
<s2_third name="drieseng">Scenario 2 3rd developer</s2_third>
<s2_forth name="claytonharbour">Scenario 2 4th developer</s2_forth>
<s2_fifth name="Hala Dajani">Scenario 2 4th developer</s2_fifth>
</scenario_2>
<scenario_3>
<s3_first name="Michael C. Two">Scenario 3 1st developer</s3_first>
<s3_second name="Giuseppe Greco">Scenario 3 2nd developer</s3_second>
<s3_third name="Ian MacLean">Scenario 3 3rd developer</s3_third>
<s3_forth name="Gregory Goltsov">Scenario 3 4th developer</s3_forth>
<s3_fifth name="Michael C. Two">Scenario 3 5th developer</s3_fifth>
</scenario_3>
</study>
And, I'm using the following PHP code to print names and values of "scenario_2"'s children
$xml_temp = simplexml_load_file("db/temp.xml");
$scenarios = $xml_temp -> children();
foreach( $scenarios[2] -> children() as $scenario_2_developer){
echo $scenario_2_developer['name']. ": " . $scenario_2_developer -> nodeValue;
It prints the attributes perfectly BUT NOT the VALUE. How can I fix it, so it prints the VALUE of the node as well?
You are pretty close, however with SimpleXML there is not ->nodeValue property, just cast the element object to string and you're fine:
echo $scenario_2_developer['name'], ": ", $scenario_2_developer, "\n";
^
|
echo casts this object to string
But I really wonder who creates such an XML, numbering element names that way seems pretty counter-productive. The XML should be fixed for better use.
Every SimpleXMLElement has a property innerNode. Cast that to a string and it will be the value you're looking for.
I'm using the following XML file:
http://xml.nordicbet.com/football.xml
$xml = simplexml_load_file('http://xml.nordicbet.com/football.xml');
foreach ($xml as $gameinfo):
$kodate=$gameinfo->GameStartTime;
$status=$gameinfo->Status;
$id=$gameinfo->EventID;
$league=$gameinfo->LeagueID;
$hometeam=$gameinfo->Participant[0];
$awayteam=$gameinfo->Participant[1];
$region=$gameinfo->Region;
$sport=$gameinfo->Sport;
$season=$gameinfo->Season;
$livebet=$gameinfo->LiveBet;
These variables are working correctly, but as you see in the code, there are a lot of OutcomeSet tags, how do I go about getting the information where
<OutcomeSet type="Result" id="50001643467" name="FC Seoul - Ulsan Hyundai Horang-I">
<Outcome odds="1.75" id="50069765963" name="1">
<Participant info="Football" id="10000020100">FC Seoul</Participant></Outcome>
<Outcome odds="3.4" id="50069765964" name="X"/>
<Outcome odds="4.05" id="50069765965" name="2">
In the above code, I'm wanting to extract the 3 'odds' - so 1.75, 3.4 and 4.05 - as seperate variables which I could use in the same was as my other variables
It's the information out of any OutcomeSet tag where the type is 'Result' that I'm after
Any help much appreciated
within the foreach u can call getName method on $gameinfo variable, it will return the name of the current XML element
this code prints out the odds values
foreach ($xml as $gameinfo) {
if ("Outcome" == $gameinfo->getName()) {
echo $gameinfo->odds . "\n";
}
}
I've got a file (leaderboard.txt) that looks like this:
funkystudios
funkystudios
funkystudios
gilletteracer74
axehairgel
Ferby123
dirdam
TheWu13
Expert_Assassin
TheWu13
ocanosoup
I want to be able to read this file, and print out the number of times each person appears in the file. (Also place in order of # of times in file)
funkystudios: 3
TheWu13: 2
gilletteracer74: 1
axehairgel: 1
(and so on)
I've tried various ways but It all came down to an issue when I would try to order them correctly... I'm guessing there is a pretty easy way to do this. (I'm new to PHP...)
EDIT:
I have gotten to this point:
foreach(array_count_values(file('leaderboard.txt')) as $person => $count)
echo "{$person} : {$count}<br />\r\n";
It doesn't order by the $count, but simply who comes up first in the file.
$counted = array_count_values(file('leaderboard.txt'));
arsort($counted);
foreach($counted as $person => $count)
echo "{$person} : {$count}<br />\r\n";
I've tried iterating over the SimpleXML object with a foreach loop. I've tried using the SimpleXMLIterator with the same results.
<?xml version="1.0" ?>
<SectionResults
xmlns:ns10="http://wgs.thomsonreuters.com/clear/api/search/court-ucc-search-extension/niem/1.0"
xmlns:ns11="http://wgs.thomsonreuters.com/clear/api/search/court-search-extension/niem/1.0"
xmlns:ns12="http://wgs.thomsonreuters.com/clear/api/report/report-realProperty-extension/niem/1.0"
xmlns:ns13="http://wgs.thomsonreuters.com/clear/api/report/report-asset-extension/niem/1.0"
xmlns:ns14="http://wgs.thomsonreuters.com/clear/api/report/report-business-commerce-extension/niem/1.0"
xmlns:ns15="http://wgs.thomsonreuters.com/clear/api/search/sanction-search-extension/niem/1.0"
xmlns:ns16="http://wgs.thomsonreuters.com/clear/api/report/report-bankruptcy-extension/niem/1.0"
xmlns:ns17="http://wgs.thomsonreuters.com/clear/api/report/report-personaldata-extension/niem/1.0"
xmlns:ns18="http://wgs.thomsonreuters.com/clear/api/search/license-prolicense-search-extension/niem/1.0"
xmlns:ns19="http://wgs.thomsonreuters.com/clear/api/search/person-search-extension/niem/1.0"
xmlns:ns2="http://niem.gov/niem/structures/2.0"
xmlns:ns20="http://wgs.thomsonreuters.com/clear/api/search/business-search-extension/niem/1.0"
xmlns:ns21="http://wgs.thomsonreuters.com/clear/api/report/report-driver-vehicle-extension/niem/1.0"
xmlns:ns22="http://wgs.thomsonreuters.com/clear/api/report/report-fraud-extension/niem/1.0"
xmlns:ns23="http://wgs.thomsonreuters.com/clear/api/search/court-lawsuits-search-extension/niem/1.0"
xmlns:ns24="http://wgs.thomsonreuters.com/clear/api/report/report-lawsuit-extension/niem/1.0"
xmlns:ns25="http://wgs.thomsonreuters.com/clear/api/search/license-drivers-search-extension/niem/1.0"
xmlns:ns26="http://wgs.thomsonreuters.com/clear/api/report/report-lienjudge-extension/niem/1.0"
xmlns:ns27="http://wgs.thomsonreuters.com/clear/api/search/court-bankruptcy-search-extension/niem/1.0"
xmlns:ns28="http://wgs.thomsonreuters.com/clear/api/search/court-lienjudge-search-extension/niem/1.0"
xmlns:ns29="http://wgs.thomsonreuters.com/clear/api/report/report-docket-extension/niem/1.0"
xmlns:ns3="http://niem.gov/niem/niem-core/2.0"
xmlns:ns30="http://wgs.thomsonreuters.com/clear/api/report/report-sanction-extension/niem/1.0"
xmlns:ns31="http://wgs.thomsonreuters.com/clear/api/report/report-license-extension/niem/1.0"
xmlns:ns32="http://wgs.thomsonreuters.com/clear/api/search/npi-search-extension/niem/1.0"
xmlns:ns33="http://wgs.thomsonreuters.com/clear/api/search/court-criminal-search-extension/niem/1.0"
xmlns:ns34="http://wgs.thomsonreuters.com/clear/api/report/report-npi-extension/niem/1.0"
xmlns:ns35="http://niem.gov/niem/appinfo/2.0"
xmlns:ns36="http://wgs.thomsonreuters.com/clear/api/report/1.0"
xmlns:ns37="http://wgs.thomsonreuters.com/clear/api/report/person-report/niem/1.0"
xmlns:ns38="http://wgs.thomsonreuters.com/clear/api/report/report-asset/niem/1.0"
xmlns:ns39="http://wgs.thomsonreuters.com/clear/api/report/report-bankruptcy/niem/1.0"
xmlns:ns4="http://wgs.thomsonreuters.com/clear/api/search/license-search-extension/niem/1.0"
xmlns:ns40="http://wgs.thomsonreuters.com/clear/api/report/report-business-commerce/niem/1.0"
xmlns:ns41="http://wgs.thomsonreuters.com/clear/api/report/report-crime/niem/1.0"
xmlns:ns42="http://wgs.thomsonreuters.com/clear/api/report/report-docket/niem/1.0"
xmlns:ns43="http://wgs.thomsonreuters.com/clear/api/report/report-driver-vehicle/niem/1.0"
xmlns:ns44="http://wgs.thomsonreuters.com/clear/api/report/report-fraud/niem/1.0"
xmlns:ns45="http://wgs.thomsonreuters.com/clear/api/report/report-lawsuit/niem/1.0"
xmlns:ns46="http://wgs.thomsonreuters.com/clear/api/report/report-license/niem/1.0"
xmlns:ns47="http://wgs.thomsonreuters.com/clear/api/report/report-lienjudge/niem/1.0"
xmlns:ns48="http://wgs.thomsonreuters.com/clear/api/report/report-personaldata/niem/1.0"
xmlns:ns49="http://wgs.thomsonreuters.com/clear/api/report/report-realProperty/niem/1.0"
xmlns:ns5="http://wgs.thomsonreuters.com/clear/api/search/license-search/niem/1.0"
xmlns:ns50="http://wgs.thomsonreuters.com/clear/api/search/person-search/niem/1.0"
xmlns:ns51="http://wgs.thomsonreuters.com/clear/api/search/phone-search/niem/1.0"
xmlns:ns52="http://wgs.thomsonreuters.com/clear/api/search/business-search/niem/1.0"
xmlns:ns6="http://wgs.thomsonreuters.com/clear/api/report/report-crime-extension/niem/1.0"
xmlns:ns7="http://wgs.thomsonreuters.com/clear/api/report/person-report-extension/niem/1.0"
xmlns:ns8="http://wgs.thomsonreuters.com/clear/api/search/phone-search-extension/niem/1.0"
xmlns:ns9="http://wgs.thomsonreuters.com/clear/api/search/court-search/niem/1.0">
<SectionDetails>
<ns37:UserSuppliedSection>
<ns7:Address>
<ns3:LocationCityName>
GREENBAY
</ns3:LocationCityName>
<ns3:LocationPostalCode>
54311
</ns3:LocationPostalCode>
<ns3:LocationStateUSPostalServiceCode>
WI
</ns3:LocationStateUSPostalServiceCode>
<ns3:StreetFullText>
123 Main St.
</ns3:StreetFullText>
</ns7:Address>
<ns7:PersonInfo>
<ns3:PersonBirthDate>
<ns3:Date>
1982-08-12
</ns3:Date>
</ns3:PersonBirthDate>
<ns3:PersonName>
<ns3:PersonGivenName>
JOHN
</ns3:PersonGivenName>
<ns3:PersonMiddleName>
J
</ns3:PersonMiddleName>
<ns3:PersonSurName>
DOE
</ns3:PersonSurName>
</ns3:PersonName>
<ns3:PersonSSNIdentification>
<ns3:IdentificationID>
123456789
</ns3:IdentificationID>
</ns3:PersonSSNIdentification>
</ns7:PersonInfo>
</ns37:UserSuppliedSection>
</SectionDetails>
</SectionResults>
<SectionResults xmlns:ns10="http://wgs.thomsonreuters.com/clear/api/search/court-ucc-search-extension/niem/1.0" xmlns:ns11="http://wgs.thomsonreuters.com/clear/api/search/court-search-extension/niem/1.0" xmlns:ns12="http://wgs.thomsonreuters.com/clear/api/report/report-realProperty-extension/niem/1.0" xmlns:ns13="http://wgs.thomsonreuters.com/clear/api/report/report-asset-extension/niem/1.0" xmlns:ns14="http://wgs.thomsonreuters.com/clear/api/report/report-business-commerce-extension/niem/1.0" xmlns:ns15="http://wgs.thomsonreuters.com/clear/api/search/sanction-search-extension/niem/1.0" xmlns:ns16="http://wgs.thomsonreuters.com/clear/api/report/report-bankruptcy-extension/niem/1.0" xmlns:ns17="http://wgs.thomsonreuters.com/clear/api/report/report-personaldata-extension/niem/1.0" xmlns:ns18="http://wgs.thomsonreuters.com/clear/api/search/license-prolicense-search-extension/niem/1.0" xmlns:ns19="http://wgs.thomsonreuters.com/clear/api/search/person-search-extension/niem/1.0" xmlns:ns2="http://niem.gov/niem/structures/2.0" xmlns:ns20="http://wgs.thomsonreuters.com/clear/api/search/business-search-extension/niem/1.0" xmlns:ns21="http://wgs.thomsonreuters.com/clear/api/report/report-driver-vehicle-extension/niem/1.0" xmlns:ns22="http://wgs.thomsonreuters.com/clear/api/report/report-fraud-extension/niem/1.0" xmlns:ns23="http://wgs.thomsonreuters.com/clear/api/search/court-lawsuits-search-extension/niem/1.0" xmlns:ns24="http://wgs.thomsonreuters.com/clear/api/report/report-lawsuit-extension/niem/1.0" xmlns:ns25="http://wgs.thomsonreuters.com/clear/api/search/license-drivers-search-extension/niem/1.0" xmlns:ns26="http://wgs.thomsonreuters.com/clear/api/report/report-lienjudge-extension/niem/1.0" xmlns:ns27="http://wgs.thomsonreuters.com/clear/api/search/court-bankruptcy-search-extension/niem/1.0" xmlns:ns28="http://wgs.thomsonreuters.com/clear/api/search/court-lienjudge-search-extension/niem/1.0" xmlns:ns29="http://wgs.thomsonreuters.com/clear/api/report/report-docket-extension/niem/1.0" xmlns:ns3="http://niem.gov/niem/niem-core/2.0" xmlns:ns30="http://wgs.thomsonreuters.com/clear/api/report/report-sanction-extension/niem/1.0" xmlns:ns31="http://wgs.thomsonreuters.com/clear/api/report/report-license-extension/niem/1.0" xmlns:ns32="http://wgs.thomsonreuters.com/clear/api/search/npi-search-extension/niem/1.0" xmlns:ns33="http://wgs.thomsonreuters.com/clear/api/search/court-criminal-search-extension/niem/1.0" xmlns:ns34="http://wgs.thomsonreuters.com/clear/api/report/report-npi-extension/niem/1.0" xmlns:ns35="http://niem.gov/niem/appinfo/2.0" xmlns:ns36="http://wgs.thomsonreuters.com/clear/api/report/1.0" xmlns:ns37="http://wgs.thomsonreuters.com/clear/api/report/person-report/niem/1.0" xmlns:ns38="http://wgs.thomsonreuters.com/clear/api/report/report-asset/niem/1.0" xmlns:ns39="http://wgs.thomsonreuters.com/clear/api/report/report-bankruptcy/niem/1.0" xmlns:ns4="http://wgs.thomsonreuters.com/clear/api/search/license-search-extension/niem/1.0" xmlns:ns40="http://wgs.thomsonreuters.com/clear/api/report/report-business-commerce/niem/1.0" xmlns:ns41="http://wgs.thomsonreuters.com/clear/api/report/report-crime/niem/1.0" xmlns:ns42="http://wgs.thomsonreuters.com/clear/api/report/report-docket/niem/1.0" xmlns:ns43="http://wgs.thomsonreuters.com/clear/api/report/report-driver-vehicle/niem/1.0" xmlns:ns44="http://wgs.thomsonreuters.com/clear/api/report/report-fraud/niem/1.0" xmlns:ns45="http://wgs.thomsonreuters.com/clear/api/report/report-lawsuit/niem/1.0" xmlns:ns46="http://wgs.thomsonreuters.com/clear/api/report/report-license/niem/1.0" xmlns:ns47="http://wgs.thomsonreuters.com/clear/api/report/report-lienjudge/niem/1.0" xmlns:ns48="http://wgs.thomsonreuters.com/clear/api/report/report-personaldata/niem/1.0" xmlns:ns49="http://wgs.thomsonreuters.com/clear/api/report/report-realProperty/niem/1.0" xmlns:ns5="http://wgs.thomsonreuters.com/clear/api/search/license-search/niem/1.0" xmlns:ns50="http://wgs.thomsonreuters.com/clear/api/search/person-search/niem/1.0" xmlns:ns51="http://wgs.thomsonreuters.com/clear/api/search/phone-search/niem/1.0" xmlns:ns52="http://wgs.thomsonreuters.com/clear/api/search/business-search/niem/1.0" xmlns:ns6="http://wgs.thomsonreuters.com/clear/api/report/report-crime-extension/niem/1.0" xmlns:ns7="http://wgs.thomsonreuters.com/clear/api/report/person-report-extension/niem/1.0" xmlns:ns8="http://wgs.thomsonreuters.com/clear/api/search/phone-search-extension/niem/1.0" xmlns:ns9="http://wgs.thomsonreuters.com/clear/api/search/court-search/niem/1.0">
<SectionName>
SubjectSection
</SectionName>
<SectionStatus>
COMPLETE
</SectionStatus>
<SectionRecordCount>
1
</SectionRecordCount>
<SectionDetails>
<ns37:SubjectSection>
<ns7:PersonInfo>
<ns7:SSNIssuanceText>
SSN issued in WI in 1981
</ns7:SSNIssuanceText>
<ns7:SSNStartYear>
1981
</ns7:SSNStartYear>
<ns3:PersonAgeDescriptionText>
50
</ns3:PersonAgeDescriptionText>
<ns3:PersonBirthDate>
<ns3:Date>
1900-01-12
</ns3:Date>
</ns3:PersonBirthDate>
<ns3:PersonName>
<ns3:PersonGivenName>
JOHN
</ns3:PersonGivenName>
<ns3:PersonMiddleName>
J
</ns3:PersonMiddleName>
<ns3:PersonSurName>
DOE
</ns3:PersonSurName>
</ns3:PersonName>
<ns3:PersonSSNIdentification>
<ns3:IdentificationID>
123-45-6789
</ns3:IdentificationID>
<ns3:IdentificationJurisdictionText>
CA
</ns3:IdentificationJurisdictionText>
</ns3:PersonSSNIdentification>
</ns7:PersonInfo>
</ns37:SubjectSection>
</SectionDetails>
</SectionResults>
All of the namespaces are defined in the SectionResults node should I need to use them. A var_dump of the XML returns SectionName, SectionStatus and SectionRecordCount just fine. However, SectionDetails is returned as another SimpleXML Object. I've tried looping over $xml->SectionDetails->children('namespace'), but I can't get any of the information out. Any help would be greatly appreciated.
Using SimpleXML::children() is not optimal with multiple namespaces like that. An xpath query would serve you better. Example:
$path = '/SectionResults/SectionDetails/ns37:UserSuppliedSection/ns7:Address/*';
foreach ($xml->xpath($path) as $e) {
echo $e->getName() , ': ', trim($e);
echo "\n";
}