Note that there are some explanatory texts on larger screens.

plurals
  1. POSonar XML Plugin: XPath rule and namespaces
    primarykey
    data
    text
    <p>We are trying to implement the <a href="http://docs.codehaus.org/display/SONAR/XML+Plugin" rel="nofollow">Sonar XML Plugin</a> to analyze the XHTML of our project. I am having trouble with the Xpath rules and multiple namespaces. We want to run Xpath checks against files whether or not they contain several different namespaces, but that doesn't seem to be possible.</p> <p>By default Sonar auto-detects the namespace--in our case the XML or XHTML namespace--and uses the associated schema. The problem is that we use <a href="http://www.primefaces.org/" rel="nofollow">Primefaces tags</a> in our XHTML and we want to use Sonar's custom xpath validation to check some specific things with the primefaces tags. For example <code>//p:outputPanel[not(@layout='block')</code> to find specific elements in the XML files.</p> <p>We put this XPath rule into Sonar and run our checks:</p> <pre><code>mvn -f pom-xhtml.xml sonar:sonar </code></pre> <p>What happens is that on files that <strong>do not</strong> have Primefaces tags in them, and thus do not have the Primefaces namespace declared, we get the following error:</p> <pre><code>[ERROR] [13:35:54.918] Could not analyze the file /Users/...snip.../header.xhtml org.sonar.api.utils.SonarException: javax.xml.xpath.XPathExpressionException at org.sonar.plugins.xml.checks.XPathCheck.getXPathExpressionForDocument(XPathCheck.java:120) ~[na:na] ... snip ... Caused by: javax.xml.xpath.XPathExpressionException: null at org.apache.xpath.jaxp.XPathImpl.compile(XPathImpl.java:408) ~[xalan-2.7.1.jar:na] at org.sonar.plugins.xml.checks.XPathCheck.getXPathExpressionForDocument(XPathCheck.java:118) ~[na:na] ... 40 common frames omitted Caused by: org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: p ... snip ... ... 41 common frames omitted </code></pre> <p>An example of such a file might be this one line file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;s:resource xmlns:s="http://jboss.com/products/seam/taglib" xmlns="http://www.w3.org/1999/xhtml" /&gt; </code></pre> <p>As far as I can tell, because Sonar is trying to test an Xpath rule with the "p:" namespace, it errors out on files where that namespace is not declared. We would rather not add all our namespaces to all our files, as it is not needed for any other reason.</p> <p>I saw that Sonar can handle custom schemas (using the sonar.xml.schemas option), so I created one that would then import the needed namespaces into it. If Sonar uses this schema to analyze with, then all needed namespaces for the Xpath checks could be declared.</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:import namespace="http://java.sun.com/jstl/core"/&gt; &lt;xs:import namespace="http://java.sun.com/jsf/facelets"/&gt; &lt;xs:import namespace="http://java.sun.com/jsf/html"/&gt; &lt;xs:import namespace="http://jboss.com/products/seam/taglib"/&gt; &lt;xs:import namespace="http://java.sun.com/jsf/core"/&gt; &lt;xs:import namespace="http://primefaces.prime.com.tr/ui"/&gt; &lt;/xs:schema&gt; </code></pre> <p>When I try that, though, I get the following error:</p> <pre><code>[ERROR] [12:59:30.197] Could not analyze the file /Users/...snip...header.xhtml java.lang.NullPointerException: name at java.util.zip.ZipFile.getEntry(ZipFile.java:156) ~[na:1.6.0_33] ... snip ... at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) [plexus-classworlds-2.4.jar:na] </code></pre> <p>Which isn't exactly helpful. If I try a blank schema:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;/xs:schema&gt; </code></pre> <p>Then we're back to the first error. Thus sonar is successfully pointing at the custom schema, but it is not working. So it seems that Sonar (or Java?) can't handle importing other namespaces as part of an XML schema.</p> <p>Am I doing something wrong in my schema that could cause this? Has anyone solved a similar problem involving Sonar? Any advice is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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