1

Looking for a way to change the values of node in an xml file using shell.

Example of data in xml file:

<property>

<name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:postgresql://myhost/metastore</value>

</property>

Based on <name> node, change the text in <value> node. Is it achievable through sed or xmlstarlet.

What I want is like based on <name> = javax.jdo.option.ConnectionURL, change <value> to Banana, so the output would be:

<property>

    <name>javax.jdo.option.ConnectionURL</name>

    <value>Banana</value>

 </property>

Thanks in advance

1 Answer 1

1

With xmlstarlet you can achieve this using the following command:

xmlstarlet ed -u '//property[name="javax.jdo.option.ConnectionURL"]/value' -v newValue source.xml

This sets the new value newValue in the XML of source.xml.

Additional info:
Always use an XML parser to process XML files and not text-based utilities like sed.

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

Comments

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.