Note that the following is code that you had working many months ago and 
still runs fine for me.  Note that after running:

[name, machine_name] = STAXResult

the value assigned to machine_name is a PyString containing some IP 
addresses (or hostnames) separated by commas.

You then are creating a PyList named machineList from this PyString using 
the string function's split method (specifying a comma as the string 
separator) so that it contains a list of these IP addresses (or 
hostnames).

machineList = machine_name.split(',')

Here's the code that you had working many months ago and still runs fine 
for me.

<?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>
        [name, machine_name] = STAXResult
        length = len(machine_name)
        machineList = machine_name.split(',')
      </script>

      <log message="1">'Name: %s' % (name)</log>
      <log message="1">'type(machineList)=%s' % (type(machineList))</log>
      <log message="1">'machineList: %s' % (machineList)</log>
      <log message="1">'len(machineList)=%s' % (len(machineList))</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>
        name = None
        machine_name = None

        # Get the text value for the element with tag name "name"
 
        nodeList = document.getElementsByTagName("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):
                machine_name = thisChild.getNodeValue()
      </script>

      <return>[name, machine_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>

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




Sangram Bakshi <san...@gmail.com> 
08/01/2009 10:11 AM

To
Sharon Lucas/Austin/i...@ibmus
cc

Subject
Re: [staf-users] Error in using jython funtion len()






Hi Sharon,
 
If you have any updates about my observation, do let know.
Actually i have to write some jython logic in a script block , which may 
be multi lined .
 
I am not sure why this syntax error behaviour.  Do u observe the same on 
your side.
 
Regards
Sangram

On Sat, Aug 1, 2009 at 12:16 PM, Sangram Bakshi <san...@gmail.com> wrote:
Hi Sharon,
 
If i use your suggestion as :
 
  <script>length = len(machine_name)</script>
   <script>machList = machine_name.split(',')</script>

I do not get any syntax error .It works fine.
 
But if i do a 
 
<script>
 [machine_name,vmware_name] = STAXResult 
  machList = machine_name.split(',') 
 
</script >
I get syntax errors.
 
So are we not supossed to use multiple statements within a <script>   
</script>??
 
Regards
Sangram
 

 
On Sat, Aug 1, 2009 at 12:10 PM, Sangram Bakshi <san...@gmail.com> wrote:
Hi Sharon,
 
Also i tried what you had suggested :
 
 
     <script> 
        [machine_name,vmware_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">'Machine_name: %s' % (machine_name)</log>
     
 
I get the ouput as : 
type(machine_name) = org.python.core.PyString
machine_name = u80sp1_L004, u80sp1_L005, u80sp1_L006
len(machine_name) = 37
Machine_name: u80sp1_L004, u80sp1_L005, u80sp1_L006
 
 
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

Reply via email to