How to parse a xml file with a script?

I try to parse a xml file in a script module.

what is the simple way :
import java classes like javax ???
or there is existing function in jython ??? the import xml.parsers.expat dont work ?

I do this to dynamically build multi-state buttons. Basically, I store the XML data in the database and pass it to this script which I have in the script modules.
Here is an example XML file.

<data> <productType> <indicatorValue>0</indicatorValue> <displayText>Casement / Picture</displayText> <buttonValue>IFCA-CAP</buttonValue> <plcValue>3</plcValue> </productType> <productType> <indicatorValue>1</indicatorValue> <displayText>Awning / Transom</displayText> <buttonValue>IFAWN-TR</buttonValue> <plcValue>4</plcValue> </productType> <productType> <indicatorValue>2</indicatorValue> <displayText>Double / Single Hung</displayText> <buttonValue>IFSH-DH</buttonValue> <plcValue>1</plcValue> </productType> <productType> <indicatorValue>3</indicatorValue> <displayText>DH Pict/Trans</displayText> <buttonValue>IFSH-DH-P-TR</buttonValue> <plcValue>5</plcValue> </productType> <productType> <indicatorValue>4</indicatorValue> <displayText>Glider</displayText> <buttonValue>IFGL</buttonValue> <plcValue>2</plcValue> </productType> <productType> <indicatorValue>5</indicatorValue> <displayText>Triple Glider</displayText> <buttonValue>IFGLTS</buttonValue> <plcValue>8</plcValue> </productType> </data>
To parse the above XML, I would pass it to this definition as a string for the first variable, and the second variable is the name of the root node, ie “productType”. So the call would look like this:

app.Buttons.parseTypeButtonXML(xmlString, "productType")
I had to do it this way to make it dynamic. You should be able to extract whatever you need from the definition to parse your XML.

[code]# This definition parses xml for building type buttons and stores the data in a list of lists

in the format [[indicatorValue, displayText, buttonValue], [indicatorValue, displayText, buttonValue]…]

@param xmlString This is a string containing xml button defintions.

@param buttonType A string representing the root xml element, which defines

what type of button we are building.

def parseTypeButtonXML(xmlString, buttonType):
# Import the necessary definitions.
from javax.xml.parsers import DocumentBuilder, DocumentBuilderFactory
from org.xml.sax import InputSource
from org.w3c.dom import Element, Node, NodeList
from import StringReader
# Create a empty list for the button data.
buttonData = []
# Build the parser.
factory = DocumentBuilderFactory.newInstance()
db = factory.newDocumentBuilder()
inStream = InputSource()
doc = db.parse(inStream)
# Get the nodeList as elements of ‘buttonType’
nodeList = doc.getElementsByTagName(buttonType)
# Work through each sashType.
for sashType in range(nodeList.getLength()):
# create a temporary list so we can add the indicator value and the display text.
temp = []
node = nodeList.item(sashType)
if( node.getNodeType() == Node.ELEMENT_NODE ):
indicatorNode = node.getElementsByTagName(‘indicatorValue’)
displayTextNode = node.getElementsByTagName(‘displayText’)
buttonValueNode = node.getElementsByTagName(‘buttonValue’)
plcValueNode = node.getElementsByTagName(‘plcValue’)
for property in range(indicatorNode.getLength()):
if( indicatorNode.item(property).getNodeType() == Node.ELEMENT_NODE ):
if( displayTextNode.item(property).getNodeType() == Node.ELEMENT_NODE ):
if( buttonValueNode.item(property).getNodeType() == Node.ELEMENT_NODE ):
if( plcValueNode.item(property).getNodeType() == Node.ELEMENT_NODE ):
temp.append(plcValueNode.item(property).getFirstChild().getNodeValue() )
# Add additional if statements for each new node…
# Append each temp list to the buttonData list.
return buttonData

#—END of parseTypeButtonXML() DEFINITION[/code]

Pretty intense, f_jons! Mind providing a higher level description of how you are using dynamically created multistate buttons?