[program-l] Re: Python XML accessing data in sub elements

  • From: Bart Bunting <bart@xxxxxxxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Sun, 20 Nov 2022 12:05:28 -0800

Not sure what happened there. Sorry about the spam.

Regards

Bart

On 21 Nov 2022, at 7:03 am, Bart Bunting <bart@xxxxxxxxxxxxxx> wrote:

Hi there sadly, this order has still not arrived any showing delayed in
Australia post
Can you please follow this up? This is getting ridiculous now.

Regards

Bart

On 8 Nov 2022, at 4:40 am, kperry@xxxxxxxxxxxxx wrote:



You don’t need a sample to loop through all the sub branchs.



*From:* program-l-bounce@xxxxxxxxxxxxx <program-l-bounce@xxxxxxxxxxxxx> *On
Behalf Of *Travis Roth
*Sent:* Monday, November 7, 2022 12:05 PM
*To:* program-l@xxxxxxxxxxxxx
*Subject:* [program-l] Re: Python XML accessing data in sub elements



Hi,

We don’t have a sample of the XML so I think guidance will be limited.

Take a look at this page which has a tutorial with some sample XML and now
the data is accessed:

https://docs.python.org/3/library/xml.etree.elementtree.html



*From:* program-l-bounce@xxxxxxxxxxxxx <program-l-bounce@xxxxxxxxxxxxx> *On
Behalf Of *reynoldsdavid46@xxxxxxxxx
*Sent:* Monday, November 7, 2022 10:29 AM
*To:* program-l@xxxxxxxxxxxxx
*Subject:* [program-l] Python XML accessing data in sub elements



Hi,

Here is my code so far:

<code begins>

import xml.etree.ElementTree as ET

mytree=ET.parse("away in a manger.xml")

myroot=mytree.getroot()

p=0

for note in myroot.iter("pitch"):

<code ends>

This iterates through all the pitch elements in the file correctly, but I
need to access sub elements of pitch, i.e. extract the data from those sub
elements.

Any help much appreciated.



David.?

Other related posts: