I'm trying to update an attribute on a child, then write that updated element to the document. I'm running into this error: 'AttributeError: Element instance has no attribute 'getiterator' '
I made this after piecing together a bunch of tutorials and resources, so let me know if anything else stands out (not too sure what I'm doing). Thanks!
Here's what I have so far:
Inside the XML doc:
<?xml version="1.0" ?>
<notes>
<prepData a_assetType="Geometry" b_assetSel="[u'pPyramid1', u'pTorus1']"/>
<prepData a_assetType="Rig" b_assetSel="[u'pPyramid1']"/>
<prepData a_assetType="Controls" b_assetSel="[u'pPyramid1']"/>
</notes>
Write XML code:
xml_file_path = "{0}/{1}_prepData.xml".format( info_dir, asset_type )
doc = ET.parse( xml_file_path )
dom = parse( xml_file_path )
root = doc.getroot()
nodes = dom.getElementsByTagName( 'prepData' )
match = []
for node in nodes:
if node.attributes['a_assetType'].value == asset_type:
match.append( node )
for node in match:
node.setAttribute( "b_assetSel", str(asset_sel) )
out = ET.tostring( node )
dom = minidom.parseString( out )
xml_file = open("{0}/{1}_prepData.xml".format( info_dir, asset_name ), "w")
xml_file.write( dom.toprettyxml() )
xml_file.close()