jrlitm
asked on
Parsing XML using XMLReader in PHP
I am having great difficulties finding any resources on how to parse a pretty simple XML script. I have tried both simpleXML and the XMLReader tools and just cannot seem to pull the data out of the Arrays correctly.
Here is the XML code:
<stations>
<institution>
<name>Franklin</name>
<station_name>ADAC_SCU</st ation_name >
<station_name>AXIS467</sta tion_name>
<station_name>Discovery808 42</statio n_name>
<station_name>FRK_US_1</st ation_name >
</institution>
<institution>
<name>Arapahoe</name>
<station_name>ARAPUS</stat ion_name>
</institution>
<institution>
<name>East</name>
<station_name>EASTASPN</st ation_name >
</institution>
</stations>
Any assistance on how to pull this data out into a php web page and then parse it out?
Thanks
JRLITM
Here is the XML code:
<stations>
<institution>
<name>Franklin</name>
<station_name>ADAC_SCU</st
<station_name>AXIS467</sta
<station_name>Discovery808
<station_name>FRK_US_1</st
</institution>
<institution>
<name>Arapahoe</name>
<station_name>ARAPUS</stat
</institution>
<institution>
<name>East</name>
<station_name>EASTASPN</st
</institution>
</stations>
Any assistance on how to pull this data out into a php web page and then parse it out?
Thanks
JRLITM
ASKER
Thanks Roonaan.
Using this example I see the data in $xmlObj however a null is passed into $firstInstitutionName and shows empty
Do you have an example of how to pull these out using a foreach so that I have an array like the following.
institution = "Franklin"
station[0] = "ADAC_SCU"
station[1] = "AXIS467"
station[2] = "Discovery80842"
station[3] = "FRK_US_1"
Thanks
Using this example I see the data in $xmlObj however a null is passed into $firstInstitutionName and shows empty
Do you have an example of how to pull these out using a foreach so that I have an array like the following.
institution = "Franklin"
station[0] = "ADAC_SCU"
station[1] = "AXIS467"
station[2] = "Discovery80842"
station[3] = "FRK_US_1"
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$xmlObj = simplexml_load_file($xmlFi
$firstInstitutionName = (String) $xmlObj->insitution[0]->na
echo $firstInstitutionName;