2

I was looking this question xmlstarlet update an attribute and trying to replace an attribute inside a Jboss configuration file. I post here just a little part of the xml:

<?xml version='1.0' encoding='UTF-8'?>

<server xmlns="urn:jboss:domain:10.0">
    <extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
    </extensions>
    <system-properties>
        <property name="hibernate.hbm2ddl.auto" value="validate"/>
    </system-properties>
</server>

What i would like to replace is the value of hibernate.hbm2ddl.auto from validate to update

Following the previous answer i tried this command, but dont update the value:

xmlstarlet edit   --update "//property[@name='hibernate.hbm2ddl.auto']/@value"   --value "update" conf.xml

I tried to follow the full path, but the result is the same: no update.

xmlstarlet edit   --update "/server/system-properties/property[@name='hibernate.hbm2ddl.auto']/@value"   --value "update" conf.xml

2 Answers 2

3

Your file uses namespaces (xmlns="urn:jboss:domain:10.0").

xmlstarlet edit --update '//*[local-name()="property"][@name="hibernate.hbm2ddl.auto"]/@value' -v "update" conf.xml

I used //*[local-name()="property"] to bypass all namespaces in conf.xml

Sign up to request clarification or add additional context in comments.

Comments

2

In Saxon 10.0's Gizmo utility (which aims to serve similar purposes to xmlstarlet) I decided to make unprefixed names match any namespace (or none). So the equivalent would be

java net.sf.saxon.Gizmo -s:conf.xml
/>update //property[@name="hibernate.hbm2ddl.auto"]/@value with "update"
/>save conf.xml
/>quit

After years of seeing people struggling with namespaces, I'm coming to the view that having unprefixed names match any namespace is much more user-friendly.

1 Comment

That's an awesome idea! You're right, there are so many questions on SO from people stuck by namespaces. Wish this was the default behavior for XPath / XSL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.