I am currently trying to read various install.rdf files of Firefox extensions through PHP SimpleXML.
Unfortunately, there is no predefined structure of how they should look. They are always using two namespaces, " http://www.w3.org/1999/02/22-rdf-syntax-ns# " and " http://www.mozilla.org/2004/em-rdf# "
So my idea was to use XPath to get the elements of interest:
$xml = simplexml_load_string($installRDF); $namespaces = $xml->getNameSpaces(true); $xml->registerXPathNamespace('rdf', NS_RDF); $main = $xml->xpath('/rdf:RDF/rdf:Description[@rdf:about="urn:mozilla:install-manifest"]');
But there seems to be a problem with the rdf prefix of the about attribute, as it simply returns the result if there is also a prefix defined in the RDF file.
So for this it works:
<RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#" xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <RDF:Description RDF:about="urn:mozilla:install-manifest"> <em:id> extension@mozilla.org </em:id> </RDF:Description> </RDF:RDF>
But for this not:
<RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#" xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <Description about="urn:mozilla:install-manifest"> <em:id> extension@mozilla.org </em:id> </Description> </RDF>
This looks like a bug for PHP, because if I remove an attribute from XPath, I always get Description elements. But I still don't know about using namespaces in XPath, so I ask here.
source share