Note that there are some explanatory texts on larger screens.

plurals
  1. POXPath doesn't match attributes without namespace as prefix
    primarykey
    data
    text
    <p>Currently I'm trying to read different install.rdf files of Firefox extensions via PHP's SimpleXML.</p> <p>Unfortunately there's no predefined structure how they have to look. They are always using two namespaces, "<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rel="nofollow">http://www.w3.org/1999/02/22-rdf-syntax-ns#</a>" and "<a href="http://www.mozilla.org/2004/em-rdf#" rel="nofollow">http://www.mozilla.org/2004/em-rdf#</a>".</p> <p>So my idea was to use an XPath to get the elements of interest:</p> <pre><code>$xml = simplexml_load_string($installRDF); $namespaces = $xml-&gt;getNameSpaces(true); $xml-&gt;registerXPathNamespace('rdf', NS_RDF); $main = $xml-&gt;xpath('/rdf:RDF/rdf:Description[@rdf:about="urn:mozilla:install-manifest"]'); </code></pre> <p>But there seems to be a problem regarding the <code>rdf</code> prefix of the <code>about</code> attribute, because it just returns a result, if there's also a prefix defined in the RDF file.</p> <p>So for this it works:</p> <pre><code>&lt;RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#" xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt; &lt;RDF:Description RDF:about="urn:mozilla:install-manifest"&gt; &lt;em:id&gt;extension@mozilla.org&lt;/em:id&gt; &lt;/RDF:Description&gt; &lt;/RDF:RDF&gt; </code></pre> <p>But for this not:</p> <pre><code>&lt;RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#" xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt; &lt;Description about="urn:mozilla:install-manifest"&gt; &lt;em:id&gt;extension@mozilla.org&lt;/em:id&gt; &lt;/Description&gt; &lt;/RDF&gt; </code></pre> <p>This looks like a bug in PHP to me, since if I remove the attribute from the XPath I am always getting the <code>Description</code> elements. But I am not aware of using namespaces in XPath yet, so I am asking here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload