XML file modifications using sed

Hi,

During an installation process in a bash script I need to do 2 things with 2 XML files. Does the use of sed affect in any way the XML file ?

1.Add to a section in <ServerListeners> section

<ServerListener>
<BaseClass>myapp.module.WowConfigurator</BaseClass>
</ServerListener>

The below code does the job, but it doesn;t format the xml file by adding tabs and all. Is that ok from an XML file point of view?

ISLISTENER=`grep -n "myapp" $WOW_HOME/conf/Server.xml|cut -d":" -f1 |head -1`

if [ ${ISLISTENER} == "" ]
then
        INSERTLINE=`grep -n "ServerListeners" $WOW_HOME/conf/Server.xml|cut -d":" -f1 |head -1`

        sed -e ''${INSERTLINE}'a\</ServerListener>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

        sed -e ''${INSERTLINE}'a\<BaseClass>myapp.module.WowConfigurator</BaseClass>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

        sed -e ''${INSERTLINE}'a\<ServerListener>''' $WOW_HOME/conf/Server.xml > $WOW_HOME/conf/Server.xml_new
        mv $WOW_HOME/conf/Server.xml_new $WOW_HOME/conf/Server.xml

fi

  1. With a sed command I need to replace the value of a first occurrence of a parameter:

The xml file contains:

                                <IpAddress>*</IpAddress>
                                <Port>1935</Port>

And I need to replace with $BINDADDRESS and $BINDPORT variables. This I didn't manage to figure it out.

Thanks,
Bianca

You are can use any editor, including sed, on an XML document. There is no requirement to use a specific editor.

In general white space does not matter in an XML document so long as it is well-formed and valid. Basically, a document is well-formed if it follows the syntax rules of the XML specification and the elements within it are correctly nested and part of a unique root.

Hi,

The modification is done during the installation process from a bash script, this is why I cannot use an editor.

For the second issue I read 2 variables from user input and I need to replace the value in the XML file.

Thanks,
Bianca