You are setting dtdFileName as follows:

dtdFileName = 'C:/STAF/services/stax/ext/stax-extentions.dtd'  

Are you sure that file exists?  Also note that in the MyXML.xml file you 
are specifying a different DTD file: 

<!DOCTYPE stax SYSTEM "C:/STAF/services/stax/ext/staf-extensions.dtd">

David Bender
STAF/STAX Development
(512-286-5315)
IBM Austin Bldg. 903-5B002
Internet: bda...@us.ibm.com




Sangram Bakshi <san...@gmail.com> 
03/23/2009 07:25 AM

To
staf-users@lists.sourceforge.net
cc

Subject
[staf-users] Unable to parse a xml through stax job.






Hi ,
 
I am trying to parse a xml file c:\MyXML.xml through a stax job.
 
The xml file contents are :
<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE stax SYSTEM "C:/STAF/services/stax/ext/staf-extensions.dtd">
<Mydata>
<name>sangram</name>
<machine_name>M002</machine_name>
</Mydata>
 
=======================================================
 
 
I am trying to parse the above xml file from the stax job:
============================================
 
In doing so i get the error :
STAXPythonEvaluationError signal raised. Terminating job.
Line 60:Error in element type "script"
java.io.FileNotFoundException:C:\STAF\services\stax\ext\stax-extentions.dtd 
(The 
system cannot find the file specified)
 
Kindly let me know where i am going wrong:
============================================ 
<?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>
        document = STAXResult
        # Change code here to parse the document as you desire.
        # The code shown here is just an example for parsing a STAX xml 
document
        root = document.getDocumentElement()
        children = root.getChildNodes()
        msg = ''
        for i in range(children.getLength()):
          thisChild = children.item(i);
          if (thisChild.getNodeType() == Node.ELEMENT_NODE and
              thisChild.getNodeName() == 'defaultcall'):
            msg = '%s\nFound defaultcall element' % (msg)
          elif thisChild.getNodeType() == Node.COMMENT_NODE:
            # Do nothing
            continue
          elif thisChild.getNodeType() == Node.ELEMENT_NODE:
            msg = '%s\nFound %s element' % (msg, thisChild.getNodeName())
      </script>
      <message>'Some parsed data: %s' % (msg)</message>
      <log>'Some parsed data: %s' % (msg)</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)
        try:
          parseError    = 0
          builder  = factory.newDocumentBuilder()
          resolver = ParserResolver()
          builder.setEntityResolver(resolver)
          builder.setErrorHandler(resolver)
          document = builder.parse(xmlFileName)
        except SAXParseException, spe:
          parseError = 1
      </script>
      <!-- Quit if there is any parsing error -->
      <if expr="parseError">
        <sequence>
          <script>
            errmsg = 'Error occurred parsing file %s\n  line: %s\n  msg: 
%s' % (
              xmlFileName, spe.getLineNumber(), spe.getMessage()) 
          </script>         
          <log>errmsg</log>
          <message>errmsg</message>
          <terminate/>
        </sequence>
      </if>
      <return>document</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
    # Name of file containing STAX DTD (or whatever DTD you want used) to
    # when validating/parsing an xml file
    dtdFileName = 'C:/STAF/services/stax/ext/stax-extentions.dtd'  
    # 
************************************************************************ #
    # Following are the private Python 
classes                                 #
    # 
************************************************************************ #
    # This class handles XML Parsing exceptions
    class ParserException(Exception):
        pass
    
    # This class handles the exception raised by XML parser
    class ParserResolver(DefaultHandler):
        def resolveEntity (self, publicId, systemId):
            return InputSource(dtdFileName)
        def error (self, e):
            raise 'error', e
        def warning (self, e):
            raise 'warning', e
        def fatalError (self, e):
            raise 'fatal', e
  </script>
</stax>
 
 
I get the error 
 
STAXPythonEvaluationError signal raised. Terminating job.
Line 60:Error in element type "script"
java.io.FileNotFoundException:C:\STAF\services\stax\ext\stax-extentions.dtd 
(The 
system cannot find the file specified)
 
 
Kindly let me know if i am doing it wrong.
 
Regards
Sangram
 
 
 
 
 
 
 
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to