Monday 15 July 2013

Edit web.xml from command line on Linux -



Edit web.xml from command line on Linux -

i'm attempting update tomcats web.xml file command line using xmlstarlet. need add together next web-app element:

<context-param> <param-name>mobileenabled</param-name> <param-value>true</param-value> </context-param>

i've acheived using number of temporary files , xmlstarlet commands:

xmlstarlet ed -n x="http://java.sun.com/xml/ns/j2ee" -s "/x:web-app" -t elem -n "context-param" -v "$$" web.xml > tmp xmlstarlet ed -n x="http://java.sun.com/xml/ns/j2ee" -s "/x:web-app/x:context-param[text()='$$']" -t attr -n "tempattr" -v "$$" tmp > tmp1 xmlstarlet ed -n x="http://java.sun.com/xml/ns/j2ee" -u "/x:web-app/x:context-param[@tempattr]" -v "" tmp1 > tmp xmlstarlet ed -n x="http://java.sun.com/xml/ns/j2ee" -s "/x:web-app/x:context-param[@tempattr]" -t elem -n "param-name" -v "test_$$" \ -s "/x:web-app/x:context-param[@tempattr]" -t elem -n "param-value" -v "value_$$" tmp > tmp1 sed 's/ tempattr=\"[0-9]*\"//g' tmp1 > tmp

what i'd ideally want able within 1 xmlstarlet command not have create temporary files; effort far isn't working.

xmlstarlet ed -n x="http://java.sun.com/xml/ns/j2ee" -s "/x:web-app" -t elem -n "context-param" -v "$$" \ -s "/x:web-app/x:context-param[text()='$$']" -t attr -n "tempattr" -v "$$" \ -u "/x:web-app/x:context-param[@tempattr]" -v "" \ -s "/x:web-app/x:context-param[@tempattr]" -t elem -n "param-name" -v "test_$$" \ -s "/x:web-app/x:context-param[@tempattr]" -t elem -n "param-value" -v "value_$$" web.xml > tmp

this doesn't add together param-name , param-value sub elements context-param. cutdown version of web.xml available here: http://pastebin.com/ygdgk6x9

can see i'm doing wrong sec xmlstarlet command?

xml

No comments:

Post a Comment