0

I am trying to use xmlstarlet to delete an extension in wildly configuration file aka standalone.xml , but it does not seem to work.

Here is what I do:

 xmlstarlet el -v /tmp/standalone.xml |grep ejb

Which returns me the xpath of the extension I want to delete:

server/extensions/extension[@module='org.jboss.as.ejb3']

Then I try to delete it with "ed -d " , but it remains present:

 xmlstarlet  ed -d 'server/extensions/extension[@module="org.jboss.as.ejb3"]'    /tmp/standalone.xml |head

Any idea ?

Akram Ben Aissi
  • 360
  • 3
  • 6
  • Any reason you're not using Wildfly's CLI? It could be automated too and would validate your modifications (for instance I tried `/extension=org.jboss.as.ejb3:remove` which failed because I still had the `ejb3` subsystem declared ; modifying the XML directly you'd have to restart the server to be aware of that error) – Aaron Sep 26 '18 at 08:53
  • I want to do it before server startup, when the server is offline actually. – Akram Ben Aissi Sep 26 '18 at 09:09
  • Since extentions are one-liners, I'd use this `sed` command : `sed -i.bak '/ – Aaron Sep 26 '18 at 09:13
  • it is not only about extension, I will do it for the whole subsystem just after. And of course, I prefer using a single tool and syntax instead of many. – Akram Ben Aissi Sep 26 '18 at 09:14
  • Yeah, `sed` could do both but I agree `xmlstarlet` would be better. I'll check if I can see what's wrong with your command, but I haven't had great experiences with xmlstarlet so far – Aaron Sep 26 '18 at 09:30
  • 1
    I think I found the issue: xmlstarlet does not really like xmlns="urn:jboss:domain:5.0" , by removing it works. Let's find out the right option to make it work – Akram Ben Aissi Sep 26 '18 at 09:31
  • 1
    I think this is documented [here](http://xmlstar.sourceforge.net/doc/UG/ch05s01.html) – Aaron Sep 26 '18 at 09:35

1 Answers1

2

Here is the final solution, which is not hyper intuitive, because it requires to add the namespace prefix for each entity not only at the root level. (We need to repeat the d: prefix at every level of the xpath)

xmlstarlet ed -N d="urn:jboss:domain:5.0" -d "d:server/d:extensions/d:extension[@module='org.jboss.as.ejb3']"   standalone/configuration/standalone.xml

thanks to Aaron also to point out the documentation which gives a few inputs.

Akram Ben Aissi
  • 360
  • 3
  • 6
  • See also https://stackoverflow.com/questions/37407022/updating-xml-with-namespace-with-xmlstarlet-1-6-1 – npostavs Sep 26 '18 at 14:38