How to insert a new element under another with xmlstarlet?

I had a similar problem: I had a Tomcat configuration file (server.xml), and had to insert a <Resource> tag with pre-defined attributes into the <GlobalNamingResources> section. Here is how it looked before: <GlobalNamingResources> <!– Editable user database that can also be used by UserDatabaseRealm to authenticate users –> <Resource name=”UserDatabase” auth=”Container” type=”org.apache.catalina.UserDatabase” description=”User database that … Read more

Handling long edit lists in XMLStarlet

The following breaks long xmlstarlet edit lists into a pipeline of shorter operations: xmlstarlet_max_commands=100 # max per instance; see http://sourceforge.net/tracker/?func=detail&aid=3488240&group_id=66612&atid=515106 shopt -s extglob # enable +([0-9]) as an equivalent to the regex ^[[:digit:]]+ xmlstarlet_ed() { declare -a global_parameters declare -a parameters declare -i num_commands declare -i cmd_len global_parameters=( ) parameters=( ) num_commands=0 global_parameters_remaining=$1; shift while … Read more

How to declare XPath namespaces in xmlstarlet?

Explicit Namespace Declaration Adding -N s=http://www.w3.org/2000/svg and then using the s: namespace prefix works: xmlstarlet ed -N s=http://www.w3.org/2000/svg -u “/s:svg/s:defs/s:linearGradient[@id=’linearGradient6204′]/@id” -v ‘linearGradient9999′ text.txt Implicit Declaration of Default Namespace Starting with XMLStarlet v1.2.1, an explicit command line definition for the default namespace (such as is the case with OP’s SVG file) can be avoided via use … Read more