I have made a application using DomDocument & SimpleXML, but the server doesn't support DomDocument (Only SimpleXML). Now I am rewriting it, but there aren't any functions in SimpleXML like "getElementsByTagName" and "getElementById" (I only need those 2). I have searched a lot on php.net & google.com, but can't find one.
I am not that good to write my own. So, does anyone know a alternative/function/tip/script for me? :)
Thanks in advance.
Happily, if SimpleXML doesn't support those DOM-methods, it supports XPath, with the
SimpleXMLElement::xpath()
method.And searching by tag name or id, with an XPath query, shouldn't be too hard.
I suppose queries like theses should do the trick :
//*[@id='VALUE']
//TAG_NAME
For example, with the following portion of XML and code to load it :
You could find one element by its
id="plop"
with something like this :And search for all
<a>
tags with that :And the output would be the following one :
Use XPath. http://www.php.net/manual/en/simplexmlelement.xpath.php