I have a string variable that contains XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<osm attribution="http://www.openstreetmap.org/copyright" copyright="OpenStreetMap and contributors" generator="openstreetmap-cgimap 2.0.1 (3329554 spike-07.openstreetmap.org)" license="http://opendatacommons.org/licenses/odbl/1-0/" version="0.6">
<way changeset="123350178" id="26695601" timestamp="2022-07-08T08:32:16Z" uid="616103" user="Max Tenerelli" version="12" visible="true">
<nd ref="289140256"/>
<nd ref="292764243"/>
<nd ref="291616556"/>
<nd ref="292764242"/>
<nd ref="291616560"/>
<nd ref="291616561"/>
<nd ref="291616562"/>
<tag k="access" v="permissive"/>
<tag k="highway" v="service"/>
<tag k="maxspeed" v="30"/>
<tag k="name" v="Baracconi - Jacotenente"/>
<tag k="oneway" v="no"/>
<tag k="surface" v="paved"/>
</way>
</osm>
I need to read all nd node (ref value) using Python. I built this code but it is not working:
import xml.etree.ElementTree as ET
root = ET.fromstring(data)
for eir in root.findall('nodes'):
print(eir.text)
<nodes>elements. Frankly I do not even understand the question.ndelements with arefattribute and extract the attribute value:[e.get('ref') for e in root.findall('.//nd[@ref]')].