I am trying to patch several XML files using XML-patch, more specifically using this library https://github.com/dnault/xml-patch
I can properly patch any xml file that does not contain any namespace declarations. I am patching a logback.xml file and all works properly.
The problem is when I try to patch a web.xml file that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true">
<display-name>My App</display-name>
...
</web-app>
Using a xml-patch file that looks like this
<diff file="WEB-INF/web.xml">
<add sel="web-app" >
<simple>true</simple>
</add>
</diff>
When I run the patcher, I get this exception:
Caused by: com.github.dnault.xmlpatch.PatchException: no matches for selector "web-app"
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)
I am fairly confident this has to be a problem with the diff file and namespaces, which I probably have not configured properly.
I have tried adding namespace declarations to the diff file but the error is the same.
Any ideas?
add sel="*/web-app"? It seems that's the proper way to do it. See examples here : xmlpatch.sourceforge.net/srns.txtlibxmlpatch), not on Github. Glad you found something that works.:)