I have file config.xml:

<?xml version="1.0" encoding="utf-8"?> 
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" id="app" version="2.5" android-versionCode="20500"> 
<name>App title</name> 
<description>Dummy dummy text.</description> 

I'd like to change value of element.

I've tried following:

xmlstarlet edit -L -u "/_:widget/name" -v "NEW_NAME" config.xml


xmlstarlet edit -L -u "//name" -v "NEW_NAME" config.xml

But it hasn't changed the 'App title' value.

3 Answers 3


You need to specify the namespace since the name element is in the http://www.w3.org/ns/widgets namespace:

xmlstarlet edit -L -N w=http://www.w3.org/ns/widgets -u "//w:name" -v "NEW_NAME" config.xml

This command works fine, but changes every entry in the xml file. ( all fields with name )

What to enter if there are more fields with the same name. I have tried:

xml ed -L -N w=http://artifactory.jfrog.org/xsd/1.7.9 -u "//w:mailServer/port" -v "123" artifactory.config.import.xml

but nothing happens. The command however is accepted.

When I use

xml ed -L -N w=http://artifactory.jfrog.org/xsd/1.7.9 -u "//w:port" -v "999" artifactory.config.import.xml 

every item with the name port is being changed to the value 999.


Is perl an option? If so, I'd suggest it - the excellent XML::Twig library makes short work of most XML parsing problems. Including in place editing:

#!/usr/bin/env perl
use strict;
use warnings;

use XML::Twig; 

sub set_name {
    my ( $twig, $element ) = @_;
    $element -> set_text ('A NEW NAME'); 
    $twig -> flush;

my $twig = XML::Twig -> new ( pretty_print => 'indented', twig_handlers => { 'name' => \&set_name } );
$twig -> parsefile_inplace('config.xml');

(You can feed it the filename on command line, with $ARGV[0])

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .