I'm attempting to parse the XML output of a GeoIP API with PHP:
<HostipLookupResultSet version="1.0.1" xsi:noNamespaceSchemaLocation="http://www.hostip.info/api/hostip-1.0.1.xsd">
<gml:description>This is the Hostip Lookup Service</gml:description>
<gml:name>hostip</gml:name>
−
<gml:boundedBy>
<gml:Null>inapplicable</gml:Null>
</gml:boundedBy>
−
<gml:featureMember>
−
<Hostip>
<ip>111.69.232.180</ip>
<gml:name>(Unknown City?)</gml:name>
<countryName>(Unknown Country?)</countryName>
<countryAbbrev>XX</countryAbbrev>
<!-- Co-ordinates are unavailable -->
</Hostip>
</gml:featureMember>
</HostipLookupResultSet>
As a complete XML neophyte, I don;t know how to handle the extra GML components with the simplexml_load_file PHP fuynction I've been using. How could I extract the开发者_运维知识库 city name from this XML using simplexml_load_file?
I tried your case with the original GML file from a web link, and it worked out. In your provided GML (and maybe the same you tested with), there should be a problem that affects its coherency. So SimpleXML couldn't work.
Your PHP code should have no problem. I already successfully use SimpleXML to process large GML files. Not much different from XML.
精彩评论