0

hello sir,
i have a xml file like

<book>

<title>abc</title>
........
<details>
    <name>abc</name>
    .....
    <author>shakespere</author>
    <year>1980</year>
</details>
<details>
    <name>xyz</name>
     .....
    <author>anand</author>
    <year>1995</year>
</details>

</book>

i need to print the values of author,year if details.name == title
here is my code

DomTree = xml.dom.minidom.parse(file)
book = DomTree.documentElement

for t in domain.getElementsByTagName("title"):
        title_name= t.childNodes[0].data
        print "Title :", tile_name
for tname in domain.getElementsByTagName("details"):
    aname= tname.getFirstChild().getNodeValue()
    if (aname == title_name):
       for aut in tname.getElementsByTagName("author"):
          print "Author : ",aut.childNodes[0].data
       for y in tname.getElementsByTagName("year"):
          print "Year : ",y.childNodes[0].data

error:AttributeError: Element instance has no attribute 'getFirstChild'

please corrct my code to get the required output.
thanks in advance...

2
Contributors
1
Reply
35
Views
3 Years
Discussion Span
Last Post by vegaseat
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.