
Terminal - Commands tagged xml - 15 results
echo '<foo><bar/></foo>' | xmllint --format -
This is sample output - yours may be different.
<?xml version="1.0"?>
<foo>
<bar/>
</foo>
xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
This is sample output - yours may be different.
This function uses xmllint to evaluate xpaths.
Usage: xpath /path/to/element XMLfile
xml2 < file.xml | grep ^/path/to/element | cut -f2- -d=
This is sample output - yours may be different.
diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
This is sample output - yours may be different.
Diffs two xml files by formatting them first using xmllint and then invoking diff.
Usage: diffxml XMLFile1 XMLFile2
xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
This is sample output - yours may be different.
$ xpath "//head/title" index.html
<title>All commands | commandlinefu.com</title>
This function uses xmllint to evaluate xpaths.
Usage: xpath /some/xpath XMLfile
awk "/<xsd:annotation>/{h=1};!h;/<\/xsd:annotation>/{h=0}" annotatedSchema.xsd
This is sample output - yours may be different.
transforms:
<xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0">
<xsd:annotation>
<xsd:documentation>This attribute denotes the version number ot the utilized XML-schema.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
into:
<xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0">
</xsd:attribute>
Removes all lines between the lines containing "" and "", including these lines itself
Backdrop:
Sometimes when working with XML files without an graphical editor, large comment-/annotation-blocks taper the readability to walk through the file. I like to create a copy of such documents without these annotations. As the documentation itself is in documentation tags inside the annotation tags an therefore graphical editors tend to put the annotation tags in their own lines, this command removes all documentations within annotation-tags.
find -type f -name "*.xml" -exec xmllint --noout {} \;
This is sample output - yours may be different.
If everything validates, there's no output. Can be handy to run on a cron job set up to email output.
atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n}
This is sample output - yours may be different.
> atomtitles http://rss.slashdot.org/Slashdot/slashdotatom
Atomic Weight Not So Constant
20 Years of Commander Keen
Amazon Taking Down Erotica, Removing From Kindles
Humble Bundle 2 Is Live
Air Force Blocks NY Times, WaPo, Other Media
FBI Alleged To Have Backdoored OpenBSD's IPSEC Stack
Fourth Amendment Protects Hosted E-mail
McDonald's Hacked and Customer Data Stolen
MS Hypes Win7 Tablets For CES &mdash; Again
Hidden Backdoor Discovered On HP MSA2000 Arrays
Julian Assange's Online Dating Profile Leaked
Why Special Effects No Longer Impress
Why Anonymous Can't Take Down Amazon.com
Watch 200 Years of Global Growth In 4 Minutes
Google Patents Browser Highlight All Button
this simply curls the feed and runs a xpath query on it ...
wget -O - 'https://USERNAMEHERE:PASSWORDHERE@mail.google.com/mail/feed/atom' --no-check-certificate
This is sample output - yours may be different.
?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<title>Gmail - Inbox for patrick.archibald@gmail.com</title>
<tagline>New messages in your Gmail Inbox</tagline>
<fullcount>1</fullcount>
<link rel="alternate" href="http://mail.google.com/mail" type="text/html" />
<modified>2010-09-26T14:39:24Z</modified>
<entry>
<title>Your Order with Amazon.com</title>
<summary>Amazon.com Logo Thanks for your order, Patrick L Archibald! Want to manage your order online? If ...</summary>
<link rel="alternate" href="http://mail.google.com/mail?account_id=patrick.archibald@gmail.com&message_id=12b496e5d987360c&view=conv&extsrc=atom" type="text/html" />
<modified>2010-09-25T15:06:30Z</modified>
<issued>2010-09-25T15:06:30Z</issued>
<id>tag:gmail.google.com,2004:1347868102431815180</id>
<author>
<name>auto-confirm@amazon.</name>
<email>auto-confirm@amazon.com</email>
</author>
</entry>
</feed>
I use this command in my Conky script to display the number of messages in my Gmail inbox and to list the from: and subject: fields.
curl -L -s `curl -s [http://podcast.com/show.rss]` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
This is sample output - yours may be different.
Gets the latest podcast show from from your favorite Podcast. Uses curl and xmlstarlet.
Make sure you change out the items between brackets.
curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
This is sample output - yours may be different.
High Preformance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
Version 0.59s-mh4 (2000/Oct/27). Written and copyrights by Michael Hipp.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Playing MPEG stream from standard input ...
Found new ID3 Header
MPEG 2.0 layer III, 64 kbit/s, 22050 Hz joint-stereo
Ever wanted to stream your favorite podcast across the network, well now you can.
This command will parse the iTunes enabled podcast and stream the latest episode across the network through ssh encryption.
curl -u <username> http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/description | awk -F= '{print $2}'
This is sample output - yours may be different.
queued Youtube video
queued TEDTalks : The amazing intelligence of crows - Joshua Klein
queued The Fresh Prince of the Dark Side Pranks Christian TV
queued Grand Theft Auto: Chinatown Wars
queued Flight of the Conchords Ep 6 Bret, You've got it Going On
Might be able to do it in less steps with xmlstarlet, although whether that would end up being shorter overall I don't know - xmlstarlet syntax confuses the heck out of me.
Prompts for your password, or if you're a bit mental you can add your password into the command itself in the format "-u user:password".
xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1
This is sample output - yours may be different.
For debian likes, that's in python-xml package.
grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2-
This is sample output - yours may be different.
a
b
body
br
center
div
fieldset
font
form
func:function
func:result
h1
h2
h4
head
html
i
img
input
label
li
link
meta
noscript
option
p
sc
script
select
span
strong
style
table
tbody
td
textarea
th
title
tr
ul
xsl:apply-templates
xsl:attribute
xsl:call-template
xsl:choose
xsl:copy-of
xsl:for-each
xsl:if
xsl:include
xsl:otherwise
xsl:param
xsl:stylesheet
xsl:template
xsl:text
xsl:value-of
xsl:variable
xsl:when
xsl:with-param
This one will work a little better, the regular expressions it is not 100% accurate for XML parsing but it will suffice any XML valid document for sure.
sed -n 's/.*<foo>\([^<]*\)<\/foo>.*/\1/p'
This is sample output - yours may be different.
Limited, but useful construct to extract text embedded in XML tags. This will only work if bar is all on one line.
If nobody posts an alternative for the multiline sed version, I'll figure it out later...