Hi Sharon,
The function returns machine_name as :
<log message="1">'machine_name is : %s' % (machine_name)</log>
i get machine_name is : u80sp1_L004, u80sp1_L005, u80sp1_L006 (as a string i
guess)
Now i try to do a
machList = machine_name.split(','). inorder to get the elements into a list
and i get again syntax error.
Following is code i try :()
<script>
[machine_name,vmware_name] = STAXResult
machList = machine_name.split(',')
length = len(machList)
</script>
above code gives syntax error . But i think somedays back it was running
fine . Is there any precautions we
have to take while writing code in <script></script>
Kindly suggest. I seem to be stuck here.
Regards
Sangram
On Sat, Aug 1, 2009 at 10:24 AM, Sangram Bakshi <san...@gmail.com> wrote:
> Hi Sharon,
>
>
> Basically i get syntax error on trying to write any python code in
>
> it is a syntax error problem...
>
> <script>
> [machine_name] = STAXResult
>
> length = len(machine_name)
>
> </script>
>
> Python code compile failed for:
> [machine_name] =STAXResult
> print machine_name
> Traceback(innermost last):
> (no code object at line 0)
> SyntaxError : ('invalidsyntax',('<string>',3,27,' print \t\t\t length =
> len(machine_name')))
>
> Do we have to import anything inside the script tags to make the code work
> ??
>
> Regards
> Sanrgam
>
>
>
> On Sat, Aug 1, 2009 at 1:01 AM, Sangram Bakshi <san...@gmail.com> wrote:
>
>> Hi Sharon,
>>
>> Thanks for your quick reply.
>> I am rather new to xml parsing ,so your help will be highly appreciated
>> and would be a time saver.
>>
>> My intent is to parse the xml file get values from it and :
>> ===========================================
>> The XML file is :
>>
>>
>> * * <?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>
>>
>> I want to parse the above file and collect
>> 1. All the machine_name in a list variable in a variable say mac_name
>> 2. All the vmware tag attributes in a list variable say vmware_attr and
>> corresponding values in another list variable say vmware_value
>>
>> I am parsing the above in the function "parseXML" as mentioned below.
>>
>> In doing so i was getting the following problems.
>>
>> 1. I was not able to get all the mach names in the list variable mac_name
>> , i only got the last one *xyz.pxy.dxe.cde*
>> *when i want all the three u80sp1_L004 u80sp1_L004 and xyz.pxy.dxe.cde.*
>> **
>> *But when i changed the xml file a little bit i could get all the values
>> .*
>> **
>> *I had only one machine_name tag this way
>> <machine_name> u80sp1_L004,u80sp1_L004,xyz.pxy.dxe.cde<\machine_name>. It
>> worked this way.*
>> **
>> *My question how : could i still parse it with three tags with same name.
>> *
>> **
>> **
>> 2. When i collect the three machine names and return it and try to get the
>> length i get error. (length = len(mach_name))
>>
>> 3. I am not sure how to get the vmware tag attributes and vmware tag
>> values.
>>
>>
>> The code i am using is :
>>
>> I think the code need to be modified a little bit to get the values
>> properly/ or even maybe the xml format to be modified to parse properly.
>>
>>
>> <?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:/MyXml.xml'</call>
>> <script>
>>
>> [vmware_value, mach_name,vmware_attr] = STAXResult
>>
>> length = len(mach_name) /*any issue in using it this way, i
>> get error here*/
>>
>> </script>
>>
>> <log message="1">'vmware_value: %s' % (name)</log>
>> <log message="1">'mach_name: %s' % (mach_name)</log>
>> <log message="1">'vmware_attr: %s' % (vmware_attr)</log>
>>
>> </sequence>
>> </function>
>> <!-- *******************************************************************
>> -->
>> <!-- Following function is used to parse an XML file and get the text
>> -->
>> <!-- values for the name and machine_name elements
>> -->
>> <!-- *******************************************************************
>> -->
>> <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_attr = None
>> mach_name = None
>> vmware_value = None
>> # Get the text value for the element with tag name "machine_name"
>> 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):
>> name = thisChild.getNodeValue()
>> # Get the text value for the element with tag name "machine_name"
>> 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):
>> mach_name = thisChild.getNodeValue()
>>
>>
>>
>>
>> # Get the text value for the element with tag name "machine_name"
>> 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):
>> name = thisChild.getNodeValue()
>>
>> # 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):
>> vmware_value = thisChild.getNodeValue()
>> vmware_attr = thisChild.getNodeAttribure() /* I GET
>> ERROR HERE ALSO ,NOT ABLE TO GET ATTR*/
>>
>>
>> </script>
>> <return>[vmware_attr,vmware_value, mach_name]</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
>>
>> 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