{"id":10663,"date":"2024-02-08T09:06:23","date_gmt":"2024-02-08T14:06:23","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10663"},"modified":"2024-02-11T18:42:21","modified_gmt":"2024-02-11T23:42:21","slug":"python-listing-xml-tags","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10663","title":{"rendered":"Python: Listing XML tags"},"content":{"rendered":"\n<p>I was having a lot of trouble using find\/findall when parsing an XML document &#8212; turns out the namespace prefixed the tag name &#8230; so I needed to find {http:\/\/maven.apache.org\/POM\/4.0.0}groupId instead of just groupId<\/p>\n\n\n\n<p>How do you figure <em>that<\/em> out? Quickest way, for me, was just to print out all of the tag names.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom lxml import etree\n# Load POM XML into tree\ntree = etree.parse( strXMLFile )\n\n# # List all element names in XML document\nfor element in tree.iter():\n     print(element.tag)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>I was having a lot of trouble using find\/findall when parsing an XML document &#8212; turns out the namespace prefixed the tag name &#8230; so I needed to find {http:\/\/maven.apache.org\/POM\/4.0.0}groupId instead of just groupId How do you figure that out? Quickest way, for me, was just to print out all of the tag names.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1945],"tags":[1972,664,1971],"class_list":["post-10663","post","type-post","status-publish","format-standard","hentry","category-python","tag-lxml","tag-python","tag-xml"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10663"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10663\/revisions"}],"predecessor-version":[{"id":10664,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10663\/revisions\/10664"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}