I am trying to extract the associated text with the following xml tags: <satellite><beamModeMnemonic><rawDataStartTime>For now I am simply trying to print the value but eventually I would like to 'stuff' this text into variable for geoprocessing with arcpy. Below is my attempt at coding this but obviously not working. I followed a simple example from this link (Sections: Traversing the Parsed Tree & Parsed Node Attributes):http://blog.doughellmann.com/2010/03/pymotw-parsing-xml-documents-with.htmlAny suggestions on how to do this simple task?---------------------------------------------------------
from xml.etree import ElementTree
import arcpy, string, os
arcpy.env.worspace='C:/Alice/scripting/script'
with open('product.xml', 'rt') as f:
tree = ElementTree.parse(f)
#this prints all the tags and attributes, needed to know if it was reading file=yes
for node in tree.getiterator():
print node.tag, node.attrib
#this give an error!!!
for path in [ './satellite', './beamModeMnemonic', './rawDataStartTime' ]:
node = tree.find(path)
print ' node text:', node.tag
print ' node text:', node.text
The errors I get in PythonWIn are:
"print node.tag
AttributeError: 'NoneType' object has no attribute 'tag'" and
"print node.text
AttributeError: 'NoneType' object has no attribute 'text'Snippet of xml file showing tags tags required:---------------------------------------------------------------------<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<product xmlns="http://www.rsi.ca/rs2/prod/xml/schemas" copyright="RADARSAT-2 Data and Products (c) MacDonald, Dettwiler and Associates Ltd., 2011 - All Rights Reserved." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rsi.ca/rs2/prod/xml/schemas schemas/rs2prod_product.xsd">
<productId>PDS_01583330</productId>
<documentIdentifier>RN-RP-51-2713, Issue 1/8</documentIdentifier>
<sourceAttributes>
<satellite>RADARSAT-2</satellite>
<sensor>SAR</sensor>
<inputDatasetId>/Fred/rsat2/166026P</inputDatasetId>
<imageId>128973</imageId>
<inputDatasetFacilityId>Not Specified</inputDatasetFacilityId>
<beamModeId>110</beamModeId>
<beamModeMnemonic>S6</beamModeMnemonic>
<rawDataStartTime>2011-04-18T12:32:56.257634Z</rawDataStartTime>
<
<fullResolutionImageData pole="HV">imagery_HV.tif</fullResolutionImageData>
</imageAttributes>
</product>