Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read the XML files
#7
Hi Snippat,

In my XML file i have below data, multiple object having similar data with different object IDs

from bs4 import BeautifulSoup as bsp

xml_file=open("E:\\Python\\MyLearning\\TestFiles\\MY.xml", "r+")
soup_xml = bsp(xml_file, 'xml')

pm=soup_xml.find_all('PMTarget', {'MType':"ABC"})
data=pm.find('ID')
print (data)
Error:
Traceback (most recent call last): File "E:/Python/MyLearning/Learning.py", line 230, in <module> data=pm.find('ID') File "C:\Python3.6.5\lib\site-packages\bs4\element.py", line 1807, in __getattr__ "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
XML FILE:
<DN>test-1/check-1</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>16365</BYTES_IN>
<BYTES_OUT>1560</BYTES_OUT>
<CONNECTIONS>8</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<EXECUTION_T>525</EXECUTION_T>
<ID>8</ID>
</PMTarget>
</PMMOResult>
<PMMOResult>
<MO dimension="network_element">
<DN>test-1/check-2</DN>
</MO>
<PMTarget MType="ABC">
<BYTES_IN>19935</BYTES_IN>
<BYTES_OUT>1920</BYTES_OUT>
<CONNECTIONS>12</CONNECTIONS>
<CONN_OPENED>0</CONN_OPENED>
<ERRORS>0</ERRORS>
<EXECUTION_T>435</EXECUTION_T>
<ID>7</ID>
</PMTarget>
Reply


Messages In This Thread
How to read the XML files - by RajaPython - Jun-03-2018, 06:19 AM
RE: How to read the XML files - by buran - Jun-03-2018, 06:20 AM
RE: How to read the XML files - by RajaPython - Jun-03-2018, 06:24 AM
RE: How to read the XML files - by buran - Jun-03-2018, 06:47 AM
RE: How to read the XML files - by snippsat - Jun-03-2018, 08:28 AM
RE: How to read the XML files - by RajaPython - Jun-03-2018, 05:03 PM
RE: How to read the XML files - by RajaPython - Jun-04-2018, 11:34 PM
RE: How to read the XML files - by snippsat - Jun-05-2018, 08:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask app cannot read js and css files. Aggam 0 1,651 Nov-04-2020, 12:33 PM
Last Post: Aggam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020