Hi Sharon,
I am trying to parse the following XML file in the stax job:
<?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>u80sp1_L006</machine_name>
<machine_name>u80sp1_L007</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>
I am able to read all values except vmware tag values properly.
I am using the following stax job code .
While reading the vmware tags i get the error
Please do let me know what is wrong in the code .
Error is:
==================
RC:4001
Result=Caught com.ibm.staf.service.stax.STAXPythonCompileException:
File: C:\STAF\stax_jobs\parse.xml,
Line 108: Error in element type "script".
Python code compile failed for:
machname = []
vmware_value = []
vmware_attr = []
# Get the text value for the element with tag name "vmware"
nodeList = document.getElementsByTagName("machine_name")
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):
machname.append( thisChild.getNodeValue())
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
vmware_attr.append(node.attributes["id"].value)
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):
vmware_value.append(thisChild.getNodeValue())
Traceback (innermost last):
(no code object) at line 0
SyntaxError: ('invalid syntax', ('<string>', 25, 1, 'node =
nodeList.item(i)'))
Request=STAF local STAX EXECUTE HOLD file :27:C:\STAF\stax_jobs\parse.xml
The detailed code is :
=======================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="Main"/>
<function name="Main">
<sequence>
<!-- Assign the file name of a STAX xml document you want to parse -->
<call function="'parseXML'">'c:/config.xml'</call>
<script>
[machname,vmware_attr,vmware_value] = STAXResult
</script>
<log message="1">'machname=%s' % (machname)</log>
<log message="1">'vmware_attr=%s' % (vmware_attr)</log>
<log message="1">'vmware_value=%s' % (vmware_value)</log>
</sequence>
</function>
<!-- *******************************************************************
-->
<!-- 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>
machname = []
vmware_value = []
vmware_attr = []
# Get the text value for the element with tag name "vmware"
nodeList = document.getElementsByTagName("machine_name")
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):
machname.append( thisChild.getNodeValue())
nodeList = document.getElementsByTagName("vmware")
for i in range(nodeList.getLength()):
node = nodeList.item(i)
vmware_attr.append(node.attributes["id"].value)
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):
vmware_value.append(thisChild.getNodeValue())
</script>
<return>[machname,vmware_attr,vmware_value]</return>
</sequence>
</function>
<script>
# These imports only need to be done once per job, no matter
# how many xml documents are parsed
from java.io import File
from java.io import StringReader
from org.xml.sax import InputSource
from org.xml.sax import SAXParseException
from org.xml.sax.helpers import DefaultHandler
from javax.xml.parsers import DocumentBuilderFactory
from javax.xml.parsers import DocumentBuilder
from org.w3c.dom import Document
from org.w3c.dom import Element
from org.w3c.dom import Node
from org.w3c.dom import NodeList
</script>
</stax>
Regards
Sangram Bakshi
On Fri, Jul 31, 2009 at 10:57 PM, Sharon Lucas <luc...@us.ibm.com> wrote:
>
> Sangram,
>
> I need more information as you didn't provide the contents of function
> "parseXML". Perhaps it isn't returning what you think it is. You should
> add more debugging to log the value of variable machine_name and its type.
> Note that if the len() function works on PyStrings and PyList, so that's
> why it is important to understand what type of variable machine_name is, as
> well as what its value is. Also, what is the complete error information
> that you are getting. Note that it would be helpful to provide the complete
> STAX job so that we could run it to recreate the problem (e.g. you didn't
> provide function "parseXML" so I don't know what exactly it is returning).
>
> Change your STAX xml function to the following so that you can see what
> variable machine_name's value and type is and provide the log output and
> error information.
>
> <stax>
> <defaultcall function="Main"/>
> <function name="Main">
> <sequence>
> <!-- Assign the file name of a STAX xml document you want to parse
> -->
> <call function="'parseXML'">'c:/MyXml.xml'</call>
> <script>
> [name, machine_name] = STAXResult
> </script>
>
> *<log message="1">'type(machine_name)=%s' %
> (type(machine_name))</log>*
> *<log message="1">'machine_name=%s' % (machine_name)</log>*
>
> <script>length = len(machine_name)</script>
> <log message="1">'len(machine_name)=%s' % (length)</log>
>
> <log message="1">'Name: %s' % (name)</log>
> <log message="1">'Machine_name: %s' % (machine_name)</log>
> </sequence>
> </function>
> </stax>
>
> --------------------------------------------------------------
> Sharon Lucas
> IBM Austin, luc...@us.ibm.com
> (512) 286-7313 or Tieline 363-7313
>
>
>
> *Sangram Bakshi <san...@gmail.com>*
>
> 07/31/2009 11:46 AM
> To
> staf-users@lists.sourceforge.net cc
> Subject
> [staf-users] Error in using jython funtion len()
>
>
>
>
> Hi ,
>
>
> In the following stax job i am trying to read the length of a list
> machine_name.
> But i get syntax error while trying to do so . The code is highlighted in
> yellow.
>
> <stax>
> <defaultcall function="Main"/>
> <function name="Main">
> <sequence>
> <!-- Assign the file name of a STAX xml document you want to parse
> -->
> <call function="'parseXML'">'c:/MyXml.xml'</call>
> <script>
> [name, machine_name] = STAXResult
>
> length = len(machine_name) ========> i am getting syntax error
> here ...is this a wrong way to do in this section?
>
> </script>
> <log message="1">'Name: %s' % (name)</log>
> <log message="1">'Machine_name: %s' % (machine_name)</log>
> </sequence>
> </function>
> </stax>
>
> 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
>
>
------------------------------------------------------------------------------
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