New answers tagged

1

This is using XMLstarlet with paste. It can probably be made in a single call to XMLstarlet, but I'm no wizard: $ paste <(xml sel -T -t -v '//@estimated' data.xml) \ <(xml sel -T -t -v '//@fullSign' data.xml) 1469138452000 MAX Blue Line to Hillsboro 1469138664000 MAX Red Line to City Center & Beaverton 1469139140000 MAX Blue Line to ...


1

$ xml2 < sunnx.xml | awk -F= ' $1 ~ /@fullSign/ { fs=$2 ; sub(/&/,"&amp;",fs) }; $1 ~ /@estimated/ { est=$2 }; fs && est { printf "%s %s\n", est, fs; fs=est="" }' 1469138452000 MAX Blue Line to Hillsboro 1469138664000 MAX Red Line to City Center &amp; Beaverton 1469139140000 MAX Blue Line to Hillsboro ...


5

I would preprocess the data with XMLStarlet: $ xml sel -t -c '/datas/data' -nl data.xml <data> <name>Name1</name> </data><data> <name>Name2</name> </data> Then it depends on how you Python script wants to read this data. Hopefully, it's from a file or from standard input...


5

I'd use xslt. the xslt stylesheet looks like this <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/datas"> <xsl:apply-templates select="data"/> </xsl:template> <xsl:template match="data"> <data><name><xsl:...


0

With XMLStarlet: $ xml sel -t -v '//testcase/@time' -nl data.xml 20.3817


0

Use lxprintf: lxprintf -e "%s\n" total_time/@value test.xml


0

Use lxprintf from the ltXML2 toolkit (Edinburgh University), eg: $ lxprintf -e data "%s;%s;%s\n" ../id_localisation id_client key test.xml 8PJ;50C;C 8PJ;25C;D1 ESP31;70D;D2 ESP31;10D;D3 Using XSLT2 is fine, but overkill for this kind of extracting. XML FAQ: http://xml.silmaril.ie/


0

Use lxgrep from the ltXML2 toolkit (Edinburgh University), eg $ lxgrep -w A '(id|C|D)' test.xml <A> <id>123</id> <C>value1</C> <D>value2</D> </A> Using these kinds of tool is far faster and more reliable than rolling your own. XML FAQ: http://xml.silmaril.ie/


0

Using XMLStarlet: #!/bin/sh xml ed -u "//ThreadGroup[. = contains(@testname, '$1')]/@enabled" -v "true" -u "//ThreadGroup[. = not(contains(@testname, '$1'))]/@enabled" -v "false" Assuming your XML is valid (I added a <SomeTag> root tag, and properly delimited the empty <ThreadGroup> node with />. I also set the enabled attributes to ...


0

To parse XML, use an XML parser. XMLStarlet is a command line XML parser that is very good for this sort of situation. Assuming that your XML is complete (it's missing </Job></Data> at the end as it is written now) then you can extract the value of the Output_Path node with $ xml --template --value-of '//Output_Path' -nl input.xml xxxxxxxx.xx....


2

Using XMLStarlet: xml ed -P \ -u '//argument[@name="protocol"]/@is-required' -v true \ -u '//argument[@name="protocol"]/@default-value' -v tcp \ -u '//argument[@name="port"]/@is-required' -v true \ -u '//argument[@name="port"]/@default-value' -v 7223 \ -u '//argument[@name="username"]/@is-required' -v true \ -u '//argument[@name="...


1

In general, XML processing should be done with an XML parser. UPDATE: In fact, I think it's unfortunate that this answer was picked as the "accepted answer" since @SatoKatsura's answer is in all ways correct and better. It uses a proper XML parser and it is shorter. See also comments from @cas to my answer. XML parsing really should not be attempted with ...


2

Try this, then: xmlstarlet sel -t -v //Output_Path -nl data.xml



Top 50 recent answers are included