Hi ,
This is not really related to STAF and STAX , but would be a time saver .I
am quite new to jython xml parsing using document builder.
I am trying to read a xml file of the following format in the staf and stax
job xml file:
<?xml version="1.0" encoding="utf-8"?>
<operating_system>
<unix_80sp1>
<tests type="quick_sanity_test">
<prerequisitescript>preparequicksanityscript</prerequisitescript>
<acbuildpath>acbuildpath</acbuildpath>
<testsuitscript>test quick sanity script</testsuitscript>
<testdir>quick sanity dir</testdir>
</tests>
<machine_name>u80sp1_L004</machine_name>
<machine_name>u80sp1_L005</machine_name>
<machine_name>xyz.pxy.dxe.cde</machine_name>
<vmware id="155.35.3.55">144.35.3.90</vmware>
<vmware id="155.35.3.56">144.35.3.91</vmware>
</unix_80sp1>
</operating_system>
Here machine_name tag can be n number. I need to read all the machine_name
tags in an array , so that i can use them later.
Also i need to read all the vmware tags in an array (both value and
attributes) so that i can use them later. The number of vmware tags can
again be n numbers.
I am trying the following code :
<!-- *******************************************************************
-->
<!-- Following function is used to parse an XML file and return the DOM
-->
<!-- document object
-->
<!-- *******************************************************************
-->
<function name="parseXML" scope="local">
<function-list-args>
<function-required-arg name="xmlFileName">
Name of file containing XML to be parsed
</function-required-arg>
</function-list-args>
<sequence>
<!-- Parse the XML -->
<script>
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(1)
factory.setIgnoringElementContentWhitespace(0)
builder = factory.newDocumentBuilder()
document = builder.parse(xmlFileName)
</script>
<script>
vmware = None
machine_name = None
# Get the text value for the element with tag name "vmware"
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
machine_name = thisChild.getNodeValue()
# Get the text value for the element with tag name "machine_name"
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
if node.getNodeType() == Node.ELEMENT_NODE:
children = node.getChildNodes()
for j in range(children.getLength()):
thisChild = children.item(j)
if (thisChild.getNodeType() == Node.TEXT_NODE):
machine_name = thisChild.getNodeValue()
</script>
<return>[machine_name,vmware]</return>
</sequence>
</function>
I am able to read only one value for machine_name (u80sp1_L005) and also one
value for vmware
i.e 144.35.3.91.
Also a good link to understand parsing in jython using doumentbilder factory
would be good help.
Regards
Sangram
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users