Questions tagged [xmlstarlet]

XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files using simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands.

XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files using simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands.

The main project, an overview, documentation and download page.

611 questions
38
votes
6 answers

How to insert a new element under another with xmlstarlet?

$ vim test.xml $ xmlstarlet ed -i "/config" -t elem -n "sub" -v "" test.xml But I wanted sub to be a child of config.…
simpatico
  • 10,709
  • 20
  • 81
  • 126
29
votes
3 answers

XMLStarlet does not select anything

I have a typical pom.xml, and want to print the groupId, artifactId and version, separated by colon. I think that XMLStarlet is the right tool for that. I tried several ways, but I always get an empty line. xml sel -t -m project -v groupId -o : -v…
uk4sx
  • 1,101
  • 1
  • 8
  • 11
27
votes
4 answers

Testing for an XML attribute

I have a piece of XML like so: I want to know which elements have a src attribute, which are empty and which have values. The furthest I have come is with $ xmlstarlet sel -t -m…
hendry
  • 9,725
  • 18
  • 81
  • 139
26
votes
1 answer

xmlstarlet select value

This is the xml-data:
joepd
  • 4,681
  • 2
  • 26
  • 27
22
votes
1 answer

how to update the xml file using xmlstarlet

I am using windows version of xmlstarlet to update an xml file, via windows batch file. xml edit --update "/xml/table/rec[@id=3]/@id" --value 10 %xmlfile% I expected this to update the id attribute of rec node to 10. When I run this I see the…
Schu
  • 1,124
  • 3
  • 11
  • 23
21
votes
1 answer

How to declare XPath namespaces in xmlstarlet?

I am new to xmlstarlet so hoping this answer is a simple one. I am writing a script to modify Inkscape SVG files from the command line. I chose the tool xmlstarlet. After testing the command syntax on test files, I am having trouble on the real SVG…
John W
  • 561
  • 1
  • 5
  • 17
17
votes
1 answer

Extracting and dumping elements using xmlstarlet

I am looking for a way to extract and print an element from my xml using xmlstarlet; for example if my xml is Harry Potter
shrijeet
  • 173
  • 1
  • 1
  • 4
15
votes
3 answers

how to? xmlstarlet to extract HTML data by id

I have a simple task that has me pulling my hair out, i'm sure i'm very close. here is my xhtml file:
matt stucky
  • 165
  • 2
  • 8
13
votes
2 answers

xmlstarlet sel output new line between values

I have the following XML I do get the correct values from the attributes but I want to have them separated on by a new line for further processing. When using the command xmlstarlet…
Dany
  • 735
  • 1
  • 8
  • 27
9
votes
5 answers

Parsing XML and replacing specific elements or attribute values via shell script

For the below xml ,I need to replace for CLASSA to failed. CLASSA
Neethu Lalitha
  • 3,031
  • 4
  • 35
  • 60
8
votes
1 answer

How do I insert an element directly after another element with XMLStarlet?

With this example XML: How do I insert element directly after the element using XMLStarlet?
Todd
  • 430
  • 1
  • 5
  • 9
8
votes
2 answers

How to install/setup XMLStarlet in Linux?

I'm fairly new to Linux and shell scripting; and have a requirement to parse and query an xml. I was able to find and use XML starlet for Windows successfully. However, my goal is to have that run on Linux via a shell script. Can anyone please share…
Rishi
  • 91
  • 1
  • 1
  • 3
8
votes
2 answers

Select node by its text value in xmlstarlet

I am trying to extract the value of the 'Value' node, where the 'Key' node is 'state' within a bash shell: