PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey I am trying to figure out how to extract individual data from an XML document. So far I have the following example which extracts information from XBOX LIVE and displays it as XML: http://www.x2i4eva.com/xbox/test2.php?gamertag=x2i4eva
I am using this script (the $_GET obtains the value inserted into the textbox on the example page i just gave):
However that just displays the whole document as a rather unfriendly block of text, I would like to extract some of the information from that such as Gamertag and TileUrl.
When you called DOMDocument->load() with the external URL, PHP went and fetched the data from the website and created an internal representation of it. You now have a local copy that you can manipulate.
okay, this isn't displaying anything right now. The reason being I think is that as you can see here: http://www.x2i4eva.com/xbox/test2.php?gamertag=x2i4eva, the XML document is parsed using the PHP load() function and is displayed as such:
This isnt XML anymore as you can see, therefore getting the elements by tag name doesn't seem to work as there aren't any tags present. However loading the XML document in this way seems to be the only way I can do it.
That seems to print out the XML Document quite nicely. Now I Need to be able to choose say 'Gamertag' and it display 'x2i4eva' etx. I need to specify what I want to show if that makes sense. Preferably in PHP!
$xmlDoc = new DOMDocument();
$xmlDoc->load("http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=".$_GET["tag"]);
$tile_url = trim($xmlDoc->getElementsByTagName('TileUrl')->item(0)->nodeValue);
Wow it actually worked and was so simple. I was listening and I did try what you told me but couldn't get it to work so tried other methods - perhaps I was on the wrong tracks. Anyway Thank you very much for this. I very much appreciate your help.