1

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?

MarathonStudios
  • 3,983
  • 10
  • 40
  • 46
  • 1
    possible duplicate of [hostip.info - Parse API response with SimpeXML](http://stackoverflow.com/questions/4828195/hostip-info-parse-api-response-with-simpexml) – Gordon Mar 11 '11 at 13:54
  • more in http://stackoverflow.com/search?q=php+gml – Gordon Mar 11 '11 at 13:55

1 Answers1

1

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.

lionelc
  • 51
  • 2