xmlstarlet

Testing for an XML attribute

喜夏-厌秋 提交于 2019-12-20 11:20:14
问题 I have a piece of XML like so: <root> <foo src=""/> <foo src="bar"/> <foo /> </root> 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 '//foo' -v @src -n foo.xml bar Though that doesn't tell me the third foo is missing the attribute. 回答1: This will select the foos with no src attribute. /root/foo[not(@src)] For the other two tasks, I would use a mix of the expressions pointed out by @TOUDIdel and

Select node by its text value in xmlstarlet

拜拜、爱过 提交于 2019-12-19 02:49:14
问题 I am trying to extract the value of the 'Value' node, where the 'Key' node is 'state' within a bash shell: <FrontendStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" serializerVersion="1.1"> <script/> <State> <String> ... ... </String> <String> ... ... </String> <String> <Key>state</Key> <Value>WatchingLiveTV</Value> </String> <String> <Key>studiolevels</Key> <Value>1</Value> </String> <String> ... ... </String> <String> ... ... </String> </State> </FrontendStatus> I

xmlstarlet sel on large file

和自甴很熟 提交于 2019-12-18 04:14:35
问题 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? 回答1: 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

xpath html combine columns

ぐ巨炮叔叔 提交于 2019-12-13 10:52:46
问题 I'm trying to extract data from socks-proxy.net with the IP and port from the website table. I'm using these commands in linux to get the IP and port. How can I combine theme? wget -q -O - "https://socks-proxy.net" | xmllint --html --xpath "//table[@id=\"proxylisttable\"]//tr//td[1]//text()" - 2>/dev/null Output: 103.254.12.3393.12.55.94192:12:44:11 It combines the IP and it its not good that will get all the IP's from the website table wget -q -O - "https://socks-proxy.net" | xmllint --html

xmlstarlet returning the value of the first node only

最后都变了- 提交于 2019-12-13 07:39:44
问题 When running like this $ xmlstarlet sel -t -v '//department[@id="123879"]/user/@name' -n file.xml it returns only the first user's name T:106603 and an empty line. Here is the related XML code inside a file called file.xml (for testing purposes): <config name="department" version="1.11"> <xad version="1459" nocheckoutver="1701"> <!-- ... --> <department name="/fighters" id="123879" group="channel" case="none" use="no"> <replication region="4334"> <options index_name="index.html" listing="0"

Searching for XML tag by value between them and inserting a new tag in shell script

回眸只為那壹抹淺笑 提交于 2019-12-13 04:07:17
问题 Say I have this test.xml file which has these contents <d> <p> <n>hi</n> <r> <s>1.0</s> </r> </p> <p> <n>hello</n> <r> <s>1.0</s> </r> </p> </d> I want to add a new <s>2.0</s> for "hello" object as shown below. <d> <p> <n>hi</n> <r> <s>1.0</s> </r> </p> <p> <n>hello</n> <r> <s>1.0</s> <s>2.0</s> </r> </p> </d> I have to do this using shell script. There is a way of searching through the XML DOM and adding tags using xmlstarlet given here http://www.technomancy.org/xml/add-a-subnode-command

Bash - Remove XML nodes if the attribute value of a child node does not equal a specific value?

纵饮孤独 提交于 2019-12-13 02:59:18
问题 I have RSS feed, like this: <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>my feed</title> <link rel="self" href="http://myhomesite.com/articles/feed/"/> <updated>2019-11-04T12:45:00Z</updated> <id>http://myhomesite.com/articles/feed/?dt=2019-11-04T12:45:00Z</id> <entry> <id>id0</id> <link rel="alternate" type="text/html" href="https://yandex.ru/link123"/> <author> <name/> </author> <published>2019-11-04T12:45:00Z</published> <updated>2019-11-04T12:45

Iterate through XML with xmlstarlet

血红的双手。 提交于 2019-12-13 02:20:08
问题 I have the following XML: <?xml version="1.0" encoding="UTF-8"?> <test-report> <testsuite> <test name="RegisterConnection1Tests"> <testcase name="testRregisterConnection001"></testcase> <testcase name="testRegisterConnection002"></testcase> </test> <test name="RegisterConnection2Tests"> <testcase name="testRregisterConnection001"></testcase> <testcase name="testRegisterConnection002"></testcase> </test> </testsuite> </test-report> And I want the output: RegisterConnection1Tests

xmlstarlet update an attribute

牧云@^-^@ 提交于 2019-12-12 18:16:16
问题 I'm working on a script which deals with an xml file. I'd like to update an attribute value in this xml file with xmlstarlet but it doesn't work. Here is a sample of the xml file: <?xml version="1.0" encoding="UTF-8"?> <channel name="xfce4-keyboard-shortcuts" version="1.0"> <property name="commands" type="empty"> <property name="default" type="empty"> <property name="<Alt>F2" type="empty"/> <property name="<Control><Alt>Delete" type="empty"/> <property name="XF86Display" type="string" value=

get attribute value using xmlstarlet or xmllint

旧时模样 提交于 2019-12-12 12:05:03
问题 I have gone through several of questions since last two days but yet to find a solution. Here is my xml: <?xml version="1.0" encoding="UTF-8"?> <Environment xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:ve="http://www.vmware.com/schema/ovfenv" oe:id="" ve:vCenterId=""> <PropertySection> <Property oe:key="vami.hostname" oe:value="jal"/> <Property oe:key="vamitimezone" oe:value=