title: How to patch an xml file with namespaces using xml-patch and xpath?
body: <p>I am trying to patch several XML files using <strong>XML-patch</strong>, more specifically using this library <a href="https://github.com/dnault/xml-patch" rel="nofollow noreferrer">https://github.com/dnault/xml-patch</a></p>
  <p>I can properly patch any xml file that does not contain any <strong>namespace</strong> declarations. I am patching a <em>logback.xml</em> file and all works properly.</p>
  <p>The problem is when I try to patch a web.xml file that looks like this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; version=&quot;3.0&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot; metadata-complete=&quot;true&quot;&gt;
  
      &lt;display-name&gt;My App&lt;/display-name&gt;
  ...
  &lt;/web-app&gt;
  </code></pre>
  <p>Using a xml-patch file that looks like this</p>
  <pre><code>&lt;diff file=&quot;WEB-INF/web.xml&quot;&gt;
      &lt;add sel=&quot;web-app&quot; &gt;
          &lt;simple&gt;true&lt;/simple&gt;
      &lt;/add&gt;
  &lt;/diff&gt;
  </code></pre>
  <p>When I run the patcher, I get this exception:</p>
  <pre><code>Caused by: com.github.dnault.xmlpatch.PatchException: no matches for selector &quot;web-app&quot;
      at com.github.dnault.xmlpatch.Patcher.selectNodes(Patcher.java:441)
      at com.github.dnault.xmlpatch.Patcher.add(Patcher.java:252)
      at com.github.dnault.xmlpatch.Patcher.patch(Patcher.java:85)
      at com.github.dnault.xmlpatch.Patcher.patch(Patcher.java:65)
      at com.github.dnault.xmlpatch.CommandLineDriver.main(CommandLineDriver.java:62)
  </code></pre>
  <p>I am fairly confident this has to be a problem with the diff file and namespaces, which I probably have not configured properly.</p>
  <p>I have tried adding namespace declarations to the diff file but the error is the same.</p>
  <p>Any ideas?</p>