Got an answer on my Python Minidom question

Lately I am have been into python development and the interaction from Python and XML. Python has some modules to interact with modules such as SAX, MiniDom, and other packages for the XML. The email was shoot on the PyXML-SIG list which is a mailing list devoted to give support to python and xml users.The first reaction was the lxml or ElementTree proposal which seems appealing but is yet another XML manipulation framework. However since I want to learn one framework and then move on to the next. Also since I want to do a OpenOffice.org manipulation with the python in the OOo installation. I want to make sure that this code can be run for most people.So finally after some emails I got a real reply to my question about using minidom to change the attribute of some of the nodes. The first step was calling on the namespace and the next will be to use the getElementsByTagNameNS(). This function already have the node name and the attributes as methods like:OONS= ‘http://openoffice.org/2001/toolbar’doc= minidom.parse(PATH)item= doc.getElementsByTagNameNS(OONS, ‘toolbaritem’)[0]item.setAttributeNS(OONS, ‘toolbar:visible’, ‘true’)fp= open(PATH, ‘wb’)doc.writexml(fp)fp.close()The next function is setAttributeNS to have the writexml() to overwrite the changes. The only issues I am having is figuring out the 0 option from the getElementByTagNameNS(). I can’t really figure out if this is a count within the node or within the tree. I’ll be testing this snippet and come up with a script to modify the XML to simplify the toolbars.

Advertisements