Parsing XML response with repeated tags
<p>This is my XML response - </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Dataset name="aggregations/g/ds083.2/2/TP"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xml.opendap.org/ns/DAP2"
xsi:schemaLocation="http://xml.opendap.org/ns/DAP2  http://xml.opendap.org/dap/dap2.xsd" &gt;

&lt;Attribute name="NC_GLOBAL" type="Container"&gt;
    &lt;Attribute name="Originating_or_generating_Center" type="String"&gt;
        &lt;value&gt;US National Weather Service, National Centres for Environmental Prediction (NCEP)&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Originating_or_generating_Subcenter" type="String"&gt;
        &lt;value&gt;0&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="GRIB_table_version" type="String"&gt;
        &lt;value&gt;2,1&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Type_of_generating_process" type="String"&gt;
        &lt;value&gt;Forecast&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Analysis_or_forecast_generating_process_identifier_defined_by_originating_centre" type="String"&gt;
        &lt;value&gt;Analysis from GDAS (Global Data Assimilation System)&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="file_format" type="String"&gt;
        &lt;value&gt;GRIB-2&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Conventions" type="String"&gt;
        &lt;value&gt;CF-1.6&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="history" type="String"&gt;
        &lt;value&gt;Read using CDM IOSP GribCollection v3&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="featureType" type="String"&gt;
        &lt;value&gt;GRID&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="_CoordSysBuilder" type="String"&gt;
        &lt;value&gt;ucar.nc2.dataset.conv.CF1Convention&lt;/value&gt;
    &lt;/Attribute&gt;
&lt;/Attribute&gt;

&lt;Grid  name="Temperature_isobaric"&gt;
    &lt;Attribute name="long_name" type="String"&gt;
        &lt;value&gt;Temperature @ Isobaric surface&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="units" type="String"&gt;
        &lt;value&gt;K&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="abbreviation" type="String"&gt;
        &lt;value&gt;TMP&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="missing_value" type="Float32"&gt;
        &lt;value&gt;NaN&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="grid_mapping" type="String"&gt;
        &lt;value&gt;LatLon_Projection&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="coordinates" type="String"&gt;
        &lt;value&gt;reftime3 time3 isobaric3 lat lon &lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib_Variable_Id" type="String"&gt;
        &lt;value&gt;VAR_7-0--1-0_L100&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Parameter" type="Int32"&gt;
        &lt;value&gt;0&lt;/value&gt;
        &lt;value&gt;0&lt;/value&gt;
        &lt;value&gt;0&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Parameter_Discipline" type="String"&gt;
        &lt;value&gt;Meteorological products&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Parameter_Category" type="String"&gt;
        &lt;value&gt;Temperature&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Parameter_Name" type="String"&gt;
        &lt;value&gt;Temperature&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Level_Type" type="String"&gt;
        &lt;value&gt;Isobaric surface&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Attribute name="Grib2_Generating_Process_Type" type="String"&gt;
        &lt;value&gt;Forecast&lt;/value&gt;
    &lt;/Attribute&gt;
    &lt;Array name="Temperature_isobaric"&gt;
        &lt;Float32/&gt;
        &lt;dimension name="time3" size="12911"/&gt;
        &lt;dimension name="isobaric3" size="31"/&gt;
        &lt;dimension name="lat" size="181"/&gt;
        &lt;dimension name="lon" size="360"/&gt;
    &lt;/Array&gt;
    &lt;Map name="time3"&gt;
        &lt;Float64/&gt;
        &lt;dimension name="time3" size="12911"/&gt;
    &lt;/Map&gt;
    &lt;Map name="isobaric3"&gt;
        &lt;Float32/&gt;
        &lt;dimension name="isobaric3" size="31"/&gt;
    &lt;/Map&gt;
    &lt;Map name="lat"&gt;
        &lt;Float32/&gt;
        &lt;dimension name="lat" size="181"/&gt;
    &lt;/Map&gt;
    &lt;Map name="lon"&gt;
        &lt;Float32/&gt;
        &lt;dimension name="lon" size="360"/&gt;
    &lt;/Map&gt;
&lt;/Grid&gt;
</code></pre>

<p></p>

<p>I want to be able to get <em>ALL</em> the names of "Map" attribute i.e. time,isobaric,lat,lon. Currently with the below code it <em>only</em> prints out the first one. I tried iterating but it only prints the time variable n times. </p>

<pre><code> import requests

 from xml.etree import ElementTree

 response = requests.get("http://rda.ucar.edu/thredds/dodsC/aggregations/g/ds083.2/2/TP.ddx?Temperature_isobaric")

 tree = ElementTree.fromstring(response.content)

 grid = tree.find("{http://xml.opendap.org/ns/DAP2}Grid")

 map = grid.find("{http://xml.opendap.org/ns/DAP2}Map")

for child in map:
  print(child.get('name'))
</code></pre>

<p>Two small changes:</p>

<pre><code>map = grid.findall("{http://xml.opendap.org/ns/DAP2}Map")

for child in map:
  print(child.get('name'))
</code></pre>

<p><code>findall</code> gets all matches, and when you are looping over <code>child in map</code> you want to be sure that you are returning values relating to <code>child</code>.</p>

python xml xml-parsing httprequest python-3.5