Skip to content

Instantly share code, notes, and snippets.

@eliroca
Last active May 15, 2019 11:58
Show Gist options
  • Save eliroca/1ba080e9b627e0a53be41431e11b632e to your computer and use it in GitHub Desktop.
Save eliroca/1ba080e9b627e0a53be41431e11b632e to your computer and use it in GitHub Desktop.

xpath

xmllint --shell --noent MAIN.suse-openstack-cloud.xml

/ > setns docbook=http://docbook.org/ns/docbook
/ > setns xi=http://www.w3.org/2001/XInclude
xpath /docbook:set/xi:include/@href
Object is a Node Set :
Set contains 4 nodes:
1  ATTRIBUTE href
    TEXT
      content=book_cloud_deploy_crowbar.xml
2  ATTRIBUTE href
    TEXT
      content=book_cloud_admin_crowbar.xml
3  ATTRIBUTE href
    TEXT
      content=book_cloud_operations_crowbar.xml
4  ATTRIBUTE href
    TEXT
      content=book_cloud_suppl.xml

python3

from lxml import etree
root = etree.parse("MAIN.suse-openstack-cloud.xml")

namespace = dict(d="http://docbook.org/ns/docbook", xi="http://www.w3.org/2001/XInclude")

root.xpath("/d:set/xi:include/@href", namespaces=namespace)

xincludes = root.xpath("/d:set/xi:include", namespaces=namespace)
for xi in xincludes:
 print(xi.attrib.get("href"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment