The project that I’m currently working on involves translating a website that was written in Python to PHP code. The part I’m doing now requires me to send $_GET requests to a web server. The response that I get back is always in XML format, so I’m using the *simplexml_load_file()* function to fetch the result.
I need to parse through the XML that the web server sends back to me. Python had a nice library called BeautifulStoneSoup, which had a find() method that returned the contents of a specified attribute.
After looking at the list of PHP functions at http://php.net/manual/en/book.simplexml.php, I cannot seem to find anything that allows me to specify an attribute name and get the contents. Keep in mind that attribute I may be looking for is not necessarily going to always be one level deep into the XML array. It may be several dimensions into the array.
I can provide an example if this wasn’t specific enough. Thanks for the help, friends!
Xpath sounds like what your looking for. It allows for searches to be made within any level of an XML directory.
The following example looks multiple levels deep with an xml directory and checks if the description node contains whatever is held within
$txtSearchResults can then be iterated through using a foreach loop