python - Get rect tag from this XML file -
how this xml file using lxml library in python?
i couldn't find proper xpath tags.
you need handle namespaces (and empty one too):
namespaces = { "dc":"http://purl.org/dc/elements/1.1/", "cc": "http://creativecommons.org/ns#", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "svg": "http://www.w3.org/2000/svg", "myns": "http://www.w3.org/2000/svg" } tree = et.fromstring(data) rect in tree.xpath("//myns:rect", namespaces=namespaces): print rect.attrib.get("id")
where data
xml string you've provided.
for testing purposes prints rect
element id
attributes:
rect3347 rect3349 rect3351 rect3351-1 rect3351-17 rect3351-1-4 rect3397 rect3399 rect3401 rect3403
Comments
Post a Comment