[Tutor] Basic ElementTree - another question
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Feb 27 12:44:06 EST 2020
On 27/02/2020 05:59, Phil wrote:
> <gpx>
>
> <wpt lat="-32.506533000" lon="137.740017000">
> <name>1</name>
> </wpt>
> </gpx>
>
> and this is what I've currently got:
>
> <gpx>
> <wpt lat="-32.506533000" lon="137.740017000" />
> <name name="1" />
> </gpx>
>
> This is the code that generates the above file:
>
> from xml.etree import ElementTree as ET
>
> gpx = ET.Element("gpx")
>
> wpt = ET.SubElement(gpx, "wpt", lat="-32.506533000", lon=
> "137.740017000")
> name = ET.SubElement(gpx, "name", name="1")
Notice you said name was a sub-element of gpx.
That's what you got. But you want name to be a
sub-element of wpt...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list