Thursday, 25 December 2014

Python XML Parsing with Tag Specific Info



I have an XML file with a structure like the following:



<title>
<ch num="1" bk="Book1">
<ver num="1">ver1 content</ver><ver num="2">ver2 content</ver>
</ch>
<ch num="2" bk="Book1">
<ver num="1">ver1 content</ver><ver num="2">ver2 content</ver>
</ch>
<ch num="1" bk="Book2">
<ver num="1">ver1 content</ver><ver num="2">ver2 content</ver>
</ch>
</title>


Is there a way I can access individual ver content for a specific ch num and book in python? (for example, access ver num=2 of ch num=2 of bk=Book1) I've looked at a few xml module classes that parse XML, however they go by tagName, and I don't see where I can input info such as num, bk, and ch. Thanks a lot!


No comments:

Post a Comment