Currently I'm trying to read different install.rdf files of Firefox extensions via PHP's SimpleXML.
Unfortunately there's no predefined structure how they have to 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 an 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 regarding the rdf
prefix of the about
attribute, because it just returns a result, if there's 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 in PHP to me, since if I remove the attribute from the XPath I am always getting the Description
elements. But I am not aware of using namespaces in XPath yet, so I am asking here.