{"id":5520,"date":"2016-02-25T12:39:44","date_gmt":"2016-02-25T11:39:44","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=5520"},"modified":"2021-09-15T17:15:40","modified_gmt":"2021-09-15T15:15:40","slug":"xmlstarlet-a-command-line-utility-to-deal-with-xml-documents","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2016\/02\/25\/xmlstarlet-a-command-line-utility-to-deal-with-xml-documents\/","title":{"rendered":"XMLStarlet \u2013\u00a0a command-line utility to deal with XML documents"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/XMLStarlet\">https:\/\/en.wikipedia.org\/wiki\/XMLStarlet<\/a><\/li><li><a style=\"line-height: 1.6;\" href=\"https:\/\/de.wikipedia.org\/wiki\/XMLStarlet\">https:\/\/de.wikipedia.org\/wiki\/XMLStarlet<\/a><\/li><li><a href=\"http:\/\/xmlstar.sourceforge.net\">http:\/\/xmlstar.sourceforge.net<\/a><\/li><li><a href=\"http:\/\/xmlstar.sourceforge.net\/docs.php\">http:\/\/xmlstar.sourceforge.net\/docs.php<\/a><\/li><li><a href=\"http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html\">http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html<\/a>&nbsp;\u2013 User&#8217;s Guide<\/li><li><a href=\"http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html#idm47077139502176\">http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html#idm47077139502176<\/a>&nbsp;\u2013 the User&#8217;s Guide section on &#8220;Other XmlStarlet Resources&#8221; (with a few broken links)<\/li><li><a href=\"http:\/\/xmlstar.sourceforge.net\/doc\/xmlstarlet.txt\">http:\/\/xmlstar.sourceforge.net\/doc\/xmlstarlet.txt<\/a>&nbsp;\u2013 yet another document called &#8220;User&#8217;s Guide&#8221; but with more&nbsp;<strong>rather educative examples<\/strong><\/li><li><a href=\"http:\/\/www.ibm.com\/developerworks\/library\/x-starlet\">http:\/\/www.ibm.com\/developerworks\/library\/x-starlet<\/a><\/li><li><a href=\"http:\/\/www.heise.de\/ct\/inhalt\/15\/14\/172\">http:\/\/www.heise.de\/ct\/inhalt\/15\/14\/172<\/a>&nbsp;&#8212; behind a paywall; my PDF copy lives on my archive at:&nbsp;Computers\/Data_Formats\/Markup_Languages\/XML\/Addressing_and_Querying\/XPath\/<\/li><li><a href=\"http:\/\/www.freesoftwaremagazine.com\/articles\/xml_starlet\">http:\/\/www.freesoftwaremagazine.com\/articles\/xml_starlet<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">CAVEAT: &#8220;<code>xmlstarlet sel --template --value-of XPATH<\/code>&#8221; lists all values on a separate new line &#8212; but the last entry comes without a trailing new-line character. If you want to pipe xmlstarlet&#8217;s output&nbsp;into &#8220;<code>while read e; do ...; done<\/code>&#8220;, the last entry won&#8217;t get read. xmlstarlet has another option for this: &#8220;<code>--nl<\/code>&#8221; (it means: &#8220;finish each printed match with a new line&#8221;). So if you write your command line like this: &#8220;<code>xmlstarlet sel --template --value-of XPATH --nl<\/code>&#8220;, everything will be fine.<br>It took me a while to find out, that the last entry does not got processed, and then how to fix this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/en.wikipedia.org\/wiki\/XMLStarlet https:\/\/de.wikipedia.org\/wiki\/XMLStarlet http:\/\/xmlstar.sourceforge.net http:\/\/xmlstar.sourceforge.net\/docs.php http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html&nbsp;\u2013 User&#8217;s Guide http:\/\/xmlstar.sourceforge.net\/doc\/UG\/xmlstarlet-ug.html#idm47077139502176&nbsp;\u2013 the User&#8217;s Guide section on &#8220;Other XmlStarlet Resources&#8221; (with a few broken links) http:\/\/xmlstar.sourceforge.net\/doc\/xmlstarlet.txt&nbsp;\u2013 yet another document called &#8220;User&#8217;s Guide&#8221; but with more&nbsp;rather educative examples http:\/\/www.ibm.com\/developerworks\/library\/x-starlet http:\/\/www.heise.de\/ct\/inhalt\/15\/14\/172&nbsp;&#8212; behind a paywall; my PDF copy lives on my archive at:&nbsp;Computers\/Data_Formats\/Markup_Languages\/XML\/Addressing_and_Querying\/XPath\/ http:\/\/www.freesoftwaremagazine.com\/articles\/xml_starlet CAVEAT: &#8220;xmlstarlet sel &#8211;template &#8211;value-of XPATH&#8221; lists all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[851,732],"tags":[],"class_list":["post-5520","post","type-post","status-publish","format-standard","hentry","category-xmlstarlet","category-xpath"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-1r2","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=5520"}],"version-history":[{"count":1,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5520\/revisions"}],"predecessor-version":[{"id":11867,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5520\/revisions\/11867"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=5520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=5520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=5520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}