{"id":6339,"date":"2016-02-26T12:32:57","date_gmt":"2016-02-26T11:32:57","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=6339"},"modified":"2023-01-01T12:13:53","modified_gmt":"2023-01-01T11:13:53","slug":"python-and-xpath","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2016\/02\/26\/python-and-xpath\/","title":{"rendered":"Python and XPath"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/XPath#Implementations\">https:\/\/en.wikipedia.org\/wiki\/XPath#Implementations<\/a>&nbsp;has a section on Python<\/li>\n\n\n\n<li><a href=\"http:\/\/shop.oreilly.com\/product\/9780596001285.do\">http:\/\/shop.oreilly.com\/product\/9780596001285.do<\/a>&nbsp;&#8212;&nbsp;O&#8217;Reilly Media book: Python &amp; XML &#8212;&nbsp;published in 2003, you cannot use the &#8220;4DOM&#8221; samples any more &#8212; I discussed it a little in this article (on this blog):&nbsp;<a href=\"http:\/\/wp.me\/p4qjMw-1Ac\">http:\/\/wp.me\/p4qjMw-1Ac<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/xml.etree.elementtree.html#xpath-support\">https:\/\/docs.python.org\/3\/library\/xml.etree.elementtree.html#xpath-support<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/xml.etree.elementtree.html#xpath-support\">https:\/\/docs.python.org\/2\/library\/xml.etree.elementtree.html#xpath-support<\/a><\/li>\n\n\n\n<li>the Python2 and Python3 samples are practically the same, you can use identical code (apart from the &#8220;print&#8221; and &#8220;format&#8221; stuff)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I had done some XPath using XMLStarlet in a shell script, and I quite like it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feeling &#8220;safe enough&#8221; with XPath I managed to deal with the Python XPath pitfall(s), and I quite like my 1st respective XPath Python script. And of course my Python script has a nicer CLI interface than my shell script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My Python XPath pitfall briefly: You cannot (at least by my impression) start an XPath expression from the root &#8212; simply omit the root&nbsp;and you are fine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had done some XPath using XMLStarlet in a shell script, and I quite like it. Feeling &#8220;safe enough&#8221; with XPath I managed to deal with the Python XPath pitfall(s), and I quite like my 1st respective XPath Python script. And of course my Python script has a nicer CLI interface than my shell script. [&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_post_was_ever_published":false,"_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},"_share_on_mastodon":"0"},"categories":[851,732],"tags":[],"class_list":["post-6339","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-1Ef","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6339","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=6339"}],"version-history":[{"count":2,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6339\/revisions"}],"predecessor-version":[{"id":12262,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/6339\/revisions\/12262"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=6339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=6339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=6339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}