NodeList object has no attribute firstChild

0 votes

When I execute the following code I get an error as 'NodeList' object has no attribute 'firstChild'. 

from xml.dom import minidom
dat = minidom.parse('sample.xml')
tagname= dat.getElementsByTagName('item')
print(tagname.firstChild.data)

Here is my XML file:

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<food>
    <item name="breakfast">Idly</item>
    <price>$2.5</price>
    <description>
   Two idly's with chutney
   </description>
    <calories>553</calories>
</food></metadata>

What should I do?

Jul 22, 2019 in Python by Fata
• 1,050 points
4,447 views

1 answer to this question.

0 votes

Use the following piece of code:

from xml.dom import minidom
dat = minidom.parse('sample.xml')
tagname= dat.getElementsByTagName('item')
print(tagname[0].firstChild.data)
OUTPUT: Idly
answered Jul 22, 2019 by Wajiha
• 1,960 points

Related Questions In Python

0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,560 points
9,433 views
0 votes
0 answers

'module' object has no attribute 'PortScanner'

I am trying to run nmap in ...READ MORE

Jan 30, 2019 in Python by Karan
1,436 views
0 votes
1 answer
0 votes
2 answers

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

Try this: data=pd.read_csv('/your file name', delim_whitespace=Tru ...READ MORE

answered Dec 10, 2020 in Python by anonymous
• 82,840 points
132,572 views
0 votes
1 answer

Python error "AttributeError: '_Screen' object has no attribute 'mainloop'" python module turtle

Hey @Nagya, replace  wn.mainlopp() with turtle.mainloop() ...READ MORE

answered Jun 19, 2019 in Python by Faiza
7,250 views
+1 vote
3 answers

Python error "AttributeError: 'Turtle' object has no attribute 'Shape'"

Hey @Nagya, replace python.Shape("Square") with the following: python.shape("square") Python is case ...READ MORE

answered Jun 19, 2019 in Python by Faiza
21,591 views
0 votes
1 answer

Python error "AttributeError: 'str' object has no attribute 'casefold'"

Check your python version. Casefold is possible ...READ MORE

answered Jul 4, 2019 in Python by Yesha
6,394 views
0 votes
1 answer

Python error "AttributeError: '_Screen' object has no attribute 'onkeypress'"

Instead of  wn.onkeypress(go_up, "w") Try wn.onkey(go_uo, " ...READ MORE

answered Jul 5, 2019 in Python by Pooja
5,076 views
0 votes
1 answer

Difference between ElementTree and Minidom

Python allows parsing these XML documents using ...READ MORE

answered Jul 22, 2019 in Python by Wajiha
• 1,960 points
5,692 views
0 votes
1 answer

Performing divison on timedelta object in python?

Refer the following piece of code: e1=datetime.timedelta(days=32, seconds=0, ...READ MORE

answered Aug 13, 2019 in Python by Wajiha
• 1,960 points
2,713 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP