I haven't got the hang on XML. I use AJAX/PHP to retreive data that sometimes come as XML. For example like this: http://ipinfodb.com/ip_query.php?ip=66.249.68.163&timezone=false I want to use it in a webpage. I have come to think of two ways of processing the data: 1. Make a style sheet. Unwanted data can for example be put as invisible .regioncode {position:absolute; visibility: hidden;} (I haven't tried in detail) 2. use PHP preg_replace to remove unwanted portions preg-replace('/<regioncode>.*?</regioncode>/', '') It seems I haven't really understood the smart thing about XML, please help me take care of my XML data, thanks. I have seen similar questions in the XML forum, but I haven't really understood the answers. Sorry if I missed something.
You can use php's simplexml_load_string() function to read the xml elements Assuming you are capturing the output in $data variable, you can use the following code $xml = simplexml_load_string($data); $ip_address = $xml->Ip; $country_code = $xml->CountryCode; and so on... for other elements
Thank you krishmk. Your reply was exactly what I was looking for. Works perfectly, of course. This kind of forums can really be helpful. Still find it amazing to get immediate help from someone far away. I visited Chennai last December. Very interesting place. "It is a flat world."
But remember, simplexml_load_string() is only available in PHP5 so you have to make a workaround if your server is below 5.
Thanks for reminding. I upgraded tp PHP5 some 6 months ago. A few programs then broke but could be repaired quickly, I don't remember which programs. But the reason to upgrade that time was to use some routines that directly parsed a web-page (f.ex. obtained by curl) into its Document Object Model nodes. (This process somehow resembles the present problem, I suddenly realized.) It seems PHP5 has come with some new good stuff?
You could also use XSLT shylesheets to render XML Files as useable text on your pages, however the solution above is probably more use to you in this instance.