xmlstarlet

Why does this XPath expression not return the correct value in xmlstarlet?

怎甘沉沦 提交于 2019-11-30 21:25:33
问题 I'm trying to extract the contents of the 'coordinates' node in this KML file using xmlstarlet. The KML file validates fine using xmlstarlet itself. I've whittled it down to a small test file containing: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2"> <Document> <Placemark> <name>eurovelo-5 690</name> <Snippet></Snippet> <description><![CDATA[ ]]></description> <styleUrl>#style390</styleUrl> <LineString> <tessellate>1</tessellate> <coordinates> 10.146948

xmlstarlet select value

不羁岁月 提交于 2019-11-30 00:25:39
This is the xml-data: <DATA VERSION="1.0"> <TABLES> <ITEM> <identifyer V="1234"></identifyer> <property1 V="abcde"></property1> <Property2 V="qwerty"></property2> </ITEM> <ITEM> <identifyer V="5678"></identifyer> <Property1 V="zyxwv"></property1> <Property2 V="dvorak"></property2> </ITEM> </TABLES> </DATA> I am trying to find property2 of the item where identifyer has value 1234 . I can select the data: $ xmlstarlet sel -t -c "/DATA/TABLES/ITEM/identifyer [@V=1234]" test.xml <identifyer V="1234"/> Two types of output would be desirable: $ xmlstarlet <some magic> <identifyer V="1234"><

Why doesn't xmlstarlet select all nodes?

我只是一个虾纸丫 提交于 2019-11-29 15:04:14
Consider this example from w3schools : <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan

xmlstarlet sel on large file

安稳与你 提交于 2019-11-29 04:25:47
The command $ xmlstarlet sel -t -c "/collection/record" file.xml seems to load the whole file into memory, before applying the given Xpath expression. This is not usable for large XML files. Does xmlstarlet provide a streaming mode to extract subelements from a large (100G+) XML file? Since I only needed a tiny subset of XPath for large XML files, I actually implemented a little tool myself: xmlcutty . The example from my question could be written like this: $ xmlcutty -path /collection/record file.xml Xmlstarlet translates all (or most) operations into xslt transformations, so the short

xmlstarlet select value

痴心易碎 提交于 2019-11-28 22:11:07
问题 This is the xml-data: <DATA VERSION="1.0"> <TABLES> <ITEM> <identifyer V="1234"></identifyer> <property1 V="abcde"></property1> <Property2 V="qwerty"></property2> </ITEM> <ITEM> <identifyer V="5678"></identifyer> <Property1 V="zyxwv"></property1> <Property2 V="dvorak"></property2> </ITEM> </TABLES> </DATA> I am trying to find property2 of the item where identifyer has value 1234 . I can select the data: $ xmlstarlet sel -t -c "/DATA/TABLES/ITEM/identifyer [@V=1234]" test.xml <identifyer V=

Why doesn't xmlstarlet select all nodes?

痴心易碎 提交于 2019-11-28 08:55:43
问题 Consider this example from w3schools: <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per

How to add diferent attributes to each node of an xmlfile using xmlstarlet

橙三吉。 提交于 2019-11-28 06:30:38
问题 I was trying to edit an xml file using xmlstarlet in a bash script. But I found I have a problem when trying to give different values to the same attributes in the same nodes, let me show you with this example: Using this code xmlstarlet ed -L -s /foo -t elem -n bar -v "" -i //bar -t attr -n id -v bar1 $file xmlstarlet ed -L -s /foo -t elem -n bar -v "" -i //bar -t attr -n id -v bar2 $file using this i get the following result in $file: <foo> <bar id="bar1" id="bar2"/> <bar id="bar2"/> </foo>

How to insert a new element under another with xmlstarlet?

跟風遠走 提交于 2019-11-27 19:22:31
$ vim test.xml <?xml version="1.0" encoding="UTF-8" ?> <config> </config> $ xmlstarlet ed -i "/config" -t elem -n "sub" -v "" test.xml <?xml version="1.0" encoding="UTF-8"?> <sub></sub> <config> </config> But I wanted sub to be a child of config. How should I change the xpath parameter of -i ? BONUS: Is it possible to insert the child directly with an attribute and even have it set to a value? Something like: $ xmlstarlet ed -i "/config" -t elem -n "sub" -v "" -a attr -n "class" -v "com.foo" test.xml npostavs Use -s (or --subnode ) instead of -i . Regarding the bonus, you can't insert an

how to update the xml file using xmlstarlet

房东的猫 提交于 2019-11-27 06:51:24
问题 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 updated xml as expected in the command line, but the file is never updated. How can I do it, I want to stay away rewriting the whole file as the file could be big one. before update: <?xml version="1.0"?> <xml> <table> <rec id="1" /> <rec id="2" /> <rec

Handling long edit lists in XMLStarlet

岁酱吖の 提交于 2019-11-27 05:38:40
Versions of XMLStarlet found in current Linux distributions have a limit of 128 operations per xmlstarlet ed invocation, and all versions are limited by the operating system's maximum command-line length. How can this be worked around? 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