Home > Enterprise >  Change a XML file using Bash
Change a XML file using Bash

Time:10-25

I have this XML file:

<?xml version="1.0" encoding="utf-8" ?>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">1</property>
      <property name="connection.provider">1</property>
      <property name="connection.driver_class">2</property>
      <property name="connection.db">3</property> 
  </session-factory>
</hibernate-configuration>

And need to change the "property name=connection.db" to 4 using Bash.

Already tried

xmlstarlet ed -u "/hibernate-configuration/session-factory/property[@name='connection.db']" -v '4' test1.config

and

xmlstarlet ed -u  "//session-factory/property[@name='db']" -v '4' test1.config

But neither works. Any help would be appreciated.

CodePudding user response:

You need to account for the namespace. Try

xmlstarlet ed -L -N x="urn:nhibernate-configuration-2.2" -u "//x:session-factory//x:property[@name='connection.db']" -v "4"  test1.config
  • Related