Python Forum
Using Python to connect to an XML ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Python to connect to an XML ?
#7
Thanks, I had to install BeautifulSoup4 even though I had BeautifulSoup installed. That works fine

from bs4 import BeautifulSoup

with open('testxml.xml', 'r') as f:
    file = f.read()

soup = BeautifulSoup(file, 'xml')
payee = soup.find('PAYEE')

print(payee.attrs)      ## All attributes
print(payee['name'])    # Get a single one
print(payee.get('name'))    # Or - get a single one

address = soup.find('ADDRESS')
print(address.attrs)
python3 soup2.py

Output:
{'matchingenabled': '0', 'email': '', 'name': 'Transfers - inter account', 'reference': '', 'id': 'P000001'} Transfers - inter account Transfers - inter account {'street': '', 'telephone': '', 'county': '', 'city': '', 'zipcode': ''}
I will need to read up on how to loop through the array "payee" and print all or filter some. Also to learn how to reference what I call a data subset. For example "ADDRESS" is a data subset (child) of both PAYEE and INSTITUTION (data 'parents'). Quite a bit of learning and reading up.

When I used to code with other programming languages, I found the learning curve not as steep if I can use a 'debug' to inspect arrays and variables, etc. I see Python has pdb.

I see there are some GUI ones also - https://stackoverflow.com/posts/4929267/revisions
Reply


Messages In This Thread
Using Python to connect to an XML ? - by jehoshua - Jun-27-2023, 04:12 AM
RE: Using Python to connect to an XML ? - by jehoshua - Jul-04-2023, 10:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  connect sql by python using txt. file dawid294 2 617 Jan-12-2024, 08:54 PM
Last Post: deanhystad
  How to Connect to PostgreSQL Through Jump Server and SSH Tunnel using Python? nishans 1 1,408 Jan-02-2024, 10:37 AM
Last Post: khanzain
  python connect to mssql wailoonho 7 2,187 Dec-07-2023, 02:06 AM
Last Post: wailoonho
  Trying to make a bot to connect on discord with Selenium Python johnsmith43 2 70,713 Mar-21-2022, 02:56 PM
Last Post: Cloudytechnical
  How to connect Mysql databse with python and VSCode IDE madhusoodhananER 1 8,909 Oct-31-2019, 10:15 AM
Last Post: Larz60+
  Connect a Teradata DB to Python OscarBoots 10 9,222 Jan-31-2019, 10:23 PM
Last Post: OscarBoots
  Python connect to Sybase IQ FORTITUDE 1 4,895 Jan-24-2019, 02:14 AM
Last Post: micseydel
  How to connect Atom and Python? Jack_Sparrow 1 3,930 May-01-2018, 10:53 AM
Last Post: Larz60+
  connect to remote database via python script sunstar20 5 5,534 Apr-23-2018, 11:05 AM
Last Post: Gribouillis
  Can anyone Please help on fixing this python code to connect and save things on sqlit Roscoes 2 3,028 Mar-06-2018, 04:48 AM
Last Post: Roscoes

Forum Jump:

User Panel Messages

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