rblog

Changing XML attributes using Python

Doing some work trying to update J2C resources defined in WebSphere using Rational Automation Framework, actually about the same thing as described in the article “A step-by-step guide to automating the deployment of a data source by using Rational Build Forge” and I needed to do some changes in jaas.xml. Won’t go into the details why editing XML using for instance “normal” Perl is hard, but I ended up using Python and ElementTree to edit the file with a structure like this

<jaas>
	<JAASAuthData 
		alias="dmgr/databaseuser" 
		description="The database user" 
		password="thepassword" 
		userId="dbid">
	</JAASAuthData>
</jaas>

Used plenty of sources to help me out, but I do think I did use http://effbot.org/ the most – super when it comes to figuring out Python, but http://www.rexx.com/~dkuhlman/pyxmlfaq.html was also of great help!

The script I created is available here updateJaas.py The script is bound to changing jaas.xml-files, but it should be quite easy to change it for other needs as well.