xmlstarlet

Extracting and dumping elements using xmlstarlet

那年仲夏 提交于 2019-11-27 04:26:05
问题 I am looking for a way to extract and print an element from my xml using xmlstarlet; for example if my xml is <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> I would like to print out book element with price = 29.99 as: <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> I understand the xpath query to

Bash insert subnode to XML file

大兔子大兔子 提交于 2019-11-27 03:34:56
问题 Im trying to edit a config file using bash. My file looks like this: <configuration> <property> <name></name> <value></value> </property> <property> <name></name> <value></value> </property> </configuration> I want to add another couple of <property> blocks to the file. Since all property tags are enclosed inside the configuration tags the file would looks like this: <configuration> <property> <name></name> <value></value> </property> <property> <name></name> <value></value> </property>

How to insert a new element under another with xmlstarlet?

让人想犯罪 __ 提交于 2019-11-26 19:51:05
问题 $ 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"

Handling long edit lists in XMLStarlet

喜你入骨 提交于 2019-11-26 11:39:27
问题 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? 回答1: 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]