Hi Sharon,
I resolved the problem . Sorry to bother you . I was trying to split a list
, so the error .
Only a string can be split with split().
Regards
Sangram
On Mon, Aug 17, 2009 at 6:21 PM, Sangram Bakshi <san...@gmail.com> wrote:
> Hi Sharon,
>
> Sorry i have to ask this again.
>
> I had earlier enquired about syntax problems in a stax job. May be i did a
> mistake then .
>
> But i have been getting the problems again. I think i sure am coding
> properly.
>
> The following code does not seems to work , it is a very simple code:
> machnameList = machname.split(',') should not give any problems .
>
> I am parsing the 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>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 was having problems in parsing the above xml in the function parseXML. .
> After doing some indentaion in the code , tabs etc
> i was able to get it right (i observe the code compiles only with a certain
> indentation pattern).
>
>
> I get the error here as :
>
> "error in element type script"
>
> Kindly suggest some rules to code the stax job (i understand basic python
> indentation , but coding a simple line like
> machnameList = machname.split(',') should not pose any problems)
>
>
> The highlighted code gets into problems .
>
> <?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>
>
> <script>
> machnameList = machname.split(',')
>
> </script> /*I get problems here */
>
> <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>
>
> <script>
> from com.ibm.staf import STAFUtil
> action ='/acunix/utilities/quick_sanity/do_sanity.sh'
> build_path='/work/nightly_build'
> acversion='R12'
> qash_path='/acunix/work/QA/QASH'
> dir_name_source='/sangram/test.out'
> store_dir ='/sangram'
> dir_name_dest='C:/STAF/stax_jobs'
>
> </script>
>
>
> <stafcmd name="'Delaying for 100 seconds AAAAAAAA'">
> <location>'etr6506l3-aix81.ca.com'</location>
> <service>'delay'</service>
> <request>'delay 10000'</request>
> </stafcmd>
> <stafcmd name = "'Attempt to ping %s' % store_dir">
> <location>'etr6506l3-aix81.ca.com'</location>
> <service>'ping'</service>
> <request>'ping'</request>
> </stafcmd>
> <if expr="RC==0">
> <message log="1">'Ping Succeeded!!!! - RC: %s, Result: %s' % (RC,
> STAFResult)</message>
> </if>
> <stafcmd name="'Delaying for 100 seconds AAAAAAAA'">
> <location>'etr6506l3-aix81.ca.com'</location>
> <service>'delay'</service>
> <request>'delay 10000'</request>
> </stafcmd>
>
> <paralleliterate var="machName" in="machList" indexvar="i">
> <process name="'Starting Quick Sanity Testing on machine %s.....'
> % machName">
> <location>machName</location>
> <command mode="'shell'">'%s %s %s %s' % (action, build_path,
> qash_path, acversion) </command>
> <stdout>'/sangram/QuickSanityReport_%s' % machName</stdout>
> </process>
> </paralleliterate>
>
>
> <paralleliterate var="machName" in="machList" indexvar="i">
> <stafcmd name ="'Start Copying Quick Sanity Report from
> remote machine ..... '">
> <location>machName</location>
> <service>'FS'</service>
> <request>'COPY FILE /sangram/QuickSanityReport_%s
> TODIRECTORY c:/STAF/stax_jobs' % (machName)</request>
> </stafcmd>
> </paralleliterate>
>
>
> </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 = []
> nodeList = document.getElementsByTagName("machine_name")
> x = nodeList.getLength()
> 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")
> y = nodeList.getLength()
> for i in range(nodeList.getLength()):
> node = nodeList.item(i)
> id = ""
> attrList = node.getAttributes()
> for k in range(attrList.getLength()):
> thisAttr = attrList.item(k)
> if thisAttr.getNodeName() == "id":
> id = thisAttr.getNodeValue()
> vmware_attr.append(id)
> 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>
>
------------------------------------------------------------------------------
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