ClassCastException on SAX parser factory newInstance

When trying to instantiate a parser factory, if none of the weblogic classes
have been accessed, the instantiation goes well. If a weblogic class has
been accessed, then I get the following stacktrace:
java.lang.ClassCastException:
weblogic.xml.jaxp.RegistrySAXParserFactory at
javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:135) at
org.apache.xml.dtm.ref.DTMManagerDefault.getXMLReader(DTMManagerDefault.java
:589) at
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:295)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
634) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1092) at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1070) at org.jasig.portal.utils.XSLT.transform(XSLT.java:269) at
com.lat_inc.pla.ui.portal.uportal.audit.CLearningPlans.renderXML(CLearningPl
ans.java:303) at
org.jasig.portal.ChannelRenderer$Worker.run(ChannelRenderer.java:533) at
org.jasig.portal.utils.ThreadPoolWorker.runIt(ThreadPoolWorker.java:111) at
org.jasig.portal.utils.ThreadPoolWorker.runWork(ThreadPoolWorker.java:94) at
org.jasig.portal.utils.ThreadPoolWorker.run(ThreadPoolWorker.java:66)
I'm using only weblogic.jar, not external xerces and xalan jars. I've
placed the weblogic.jar file in jre/lib/ext
Thanks,
Jim Weaver
[transparent.gif]

Put your code inside a method!

Similar Messages

  • I need help using a SAX parser

    Hello,
    I have a class that goes out to the web and retrieves an xml document w/o ever writing it to disk. I like to parse that object using SAX and a class that extends HandlerBase. Can any one show me how to parse an xml document that lives in memory rather than in a file? I've found many examples, but all of them assume you are reading from a file system. Any help is greatly appreciated.
    Here is the jist of my code :
    // Class 1 makes a request to another server based on some variable data. I've created a messenger object that handles all of the communications and returns the data in a DataInputStream
    XMLMessage xml = new XMLMessage();
    xml.createRequest(args[0],args[1],args[2]);
    XMLMessenger messenger = new XMLMessenger(xml.getDoc());
    DataInputStream dis = messenger.transferDocument();
    ResponseObj resp = new ResponseObj();
    resp.read(dis);
    System.out.println(resp.getvalue1() + "*" + resp.getvalue2()+ "*");
    // Class 2 is the ResponseObj and I want to use something similar to this read method, but
    // I can't get it to work with a data stream, instead of a string that represents a file.
    public void read(String filename) throws java.lang.Exception {
    Class c = Class.forName("com.ibm.xml.parser.SAXDriver");
         org.xml.sax.Parser parser = (org.xml.sax.Parser)c.newInstance();
         parser.setDocumentHandler(this);
         parser.parse(filename);

    Thanks for you help. I've modified my read() method to work like this :
    org.xml.sax.Parser parser = new com.ibm.xml.parser.SAXDriver();
    parser.setDocumentHandler(this);
    InputSource is = new InputSource(dis);
    parser.parse(is);
    This makes sense, but I'm still not getting any thing returned from the startElement(),characters(), or endElement() methods. It reports no errors, it just doesn't happen. Do you have any suggestions on how to debug this? I'm stumped, but really need to get this working.

  • SAX Parser ClassCastException

    Guidance on the issue described below would be appreciated.
    Product Oracle Containers for J2EE Product Version 10.0.3
    Platform Microsoft Windows
    HOW TO OVERRIDE PARSER IN 10.0.3 OAS 10G PREVIEW 2
    ### Provide the full build number for the OC4J version that you are running: ###
    Oracle Application Server Containers for J2EE 10g (10.0.3.0.0) - Developer
    Preview (build 040227.1923)
    ### Which type of OC4J installation are you running? ###
    standalone OC4J installation (from zip file)
    ### If this OC4J instance is 'standalone', where was it installed? ###
    it's own dedicated ORACLE_HOME
    ### Provide the exact text and location for any error seen in a log file: ###
    java
    -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
    -Djavax.xml.parsers.TransformerFactory=org.apache.xalan.processor.TransformerFac
    toryImpl
    -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerF
    actoryImpl -Dorg.dom4j.verbose=true -DCRN_ROOT=f:\cognos\crn -jar oc4j.jar
    04/03/23 10:51:25 Node started with id=68984609063434
    04/03/23 10:51:44 log4j:WARN LogFileWatchdog: shutDownHierarchy
    04/03/23 10:51:44 log4j:WARN LogIPFControl - Unknown error during initialize
    04/03/23 10:51:44 log4j: Setting IPF internal debugging to true
    04/03/23 10:51:45 log4j:WARN No appenders could be found for logger
    (Audit.RTUsage.CAM.CRP.jcam).
    04/03/23 10:51:45 log4j:WARN Please initialize the log4j system properly.
    04/03/23 10:51:46 log4j: Log Server Port is: 9362
    04/03/23 10:51:46 log4j: Encoding set to: false
    04/03/23 10:51:46 log4j: Number of Server Worker Threads is: 10
    04/03/23 10:51:46 log4j: Encoding set to: false
    04/03/23 10:51:46 log4j: Relative file path set to:
    F:/cognos/crn/logs/crnserver.log
    04/03/23 10:51:46 log4j: Exception encountered while trying to convert
    configuration document into W3C Document.
    04/03/23 10:51:46 log4j:ERROR null
    04/03/23 10:51:47 Warning: Caught exception attempting to use JAXP to load a
    SAX XMLReader
    04/03/23 10:51:47 Warning: Exception was: java.lang.ClassCastException
    04/03/23 10:51:47 Warning: I will print the stack trace then carry on using the
    default SAX parser
    04/03/23 10:51:47 java.lang.ClassCastException
    04/03/23 10:51:47 at
    javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
    04/03/23 10:51:47 at
    org.dom4j.io.JAXPHelper.createXMLReader(JAXPHelper.java:34)
    04/03/23 10:51:47 at
    org.dom4j.io.SAXHelper.createXMLReaderViaJAXP(SAXHelper.java:80)
    04/03/23 10:51:47 at
    org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:49)
    04/03/23 10:51:47 at
    org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:528)
    04/03/23 10:51:47 at
    org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:411)
    04/03/23 10:51:47 at org.dom4j.io.SAXReader.read(SAXReader.java:277)
    04/03/23 10:51:47 at org.dom4j.io.SAXReader.read(SAXReader.java:201)
    04/03/23 10:51:47 at org.dom4j.io.SAXReader.read(SAXReader.java:190)
    04/03/23 10:51:47 at
    com.cognos.cclcfgapi.CCLStartupConfiguration.getConfigDoc
    (CCLStartupConfiguration.java:253)
    04/03/23 10:51:47 at
    com.cognos.cclcfgapi.CCLStartupConfiguration.getStartupConfigurationDocumen
    t(CCLStartupConfiguration.java:136)
    04/03/23 10:51:47 at
    com.cognos.cclcfgapi.CCLStartupConfiguration.getStartupConfigurationDocument
    (CCLStartupConfiguration.java:112)
    04/03/23 10:51:47 at
    com.cognos.cclcfgapi.CCLConfiguration.init(CCLConfiguration.java:209)
    04/03/23 10:51:47 at
    com.cognos.pogo.config.ConfigurationImpl.reconfigure(ConfigurationImpl.java:43)
    04/03/23 10:51:47 at
    com.cognos.pogo.services.DispatcherServices.startInititalServices(DispatcherServ
    ices.java:394)
    04/03/23 10:51:47 at
    com.cognos.pogo.transport.PogoServlet$PogoStartup.run(PogoServlet.java:499)
    04/03/23 10:51:47 at java.lang.Thread.run(Unknown Source)
    04/03/23 10:51:48 Oracle Application Server Containers for J2EE 10g
    (10.0.3.0.0) - Developer Preview initialized
    ### Describe in detail the problem you are having: ###
    Trying to override the parser used by our application and getting the error
    above in the console. I also have <web-app-class-loader
    search-local-classes-first="true" include-war-manifest-class-path="true" />
    set in the orion-web.xml for our application.
    I've tried various options on the command line, this seems to get the furthest
    but our app doesn't start.

    Thanks, I did try that as well.....
    E:\o10g\j2ee\home>java -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.xml.sax.driver=
    org.apache.xerces.parsers.SAXParser -Djavax.xml.parsers.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
    -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl -Xbootclasspath/a:e:\o10g\dom4j-1.
    4\dom4f-1.4\lib\tool\xerces.jar -DCRN_ROOT=f:\cognos\crn -jar oc4j.jar
    04/03/25 07:50:28 Node started with id=68984609063434
    04/03/25 07:50:35 setting transaction-timeout to:30000
    04/03/25 07:50:48 log4j:WARN LogFileWatchdog: shutDownHierarchy
    04/03/25 07:50:48 log4j:WARN LogIPFControl - Unknown error during initialize
    04/03/25 07:50:48 log4j: Setting IPF internal debugging to true
    04/03/25 07:50:49 log4j:WARN No appenders could be found for logger (Audit.RTUsage.CAM.CRP.jcam).
    04/03/25 07:50:49 log4j:WARN Please initialize the log4j system properly.
    04/03/25 07:50:50 log4j: Log Server Port is: 9362
    04/03/25 07:50:50 log4j: Encoding set to: false
    04/03/25 07:50:50 log4j: Number of Server Worker Threads is: 10
    04/03/25 07:50:50 log4j: Encoding set to: false
    04/03/25 07:50:50 log4j: Relative file path set to: F:/cognos/crn/logs/crnserver.log
    04/03/25 07:50:50 log4j: Exception encountered while trying to convert configuration document into W3C Document.
    04/03/25 07:50:50 log4j:ERROR null
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-7 JVM used memory: 8699568
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-8 JVM used memory: 8837624
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-9 JVM used memory: 8838480
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-10 JVM used memory: 8839536
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-11 JVM used memory: 8840392
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-12 JVM used memory: 8841248
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-13 JVM used memory: 8842304
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-14 JVM used memory: 8843160
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-15 JVM used memory: 8844016
    04/03/25 07:50:50 log4j: ***** Thread begin: Thread-16 JVM used memory: 8845072
    04/03/25 07:50:51 Warning: Error occurred using JAXP to load a SAXParser. Will use Aelfred instead
    04/03/25 07:50:52 Oracle Application Server Containers for J2EE 10g (10.0.3.0.0) - Developer Preview initialized

  • Sax parser problem

    hi,
    i am assuming the problem is with sax parser but i cant be sure. I am parsing a xml file (about 1.4MB) with some data in it. the parser i have created reads the xml file correctly for the most part but when at some point the
    "public void characters(char buf[], int offset, int len) throws SAXException"
    function stops working correctly....i.e it doesnt fully read read the data between the "<start>" and "</start>" element. say it reads about 100 id's correctly---for 101 ID it does this. This is just an example. Since, the problem might be with how :
    "public void characters(char buf[], int offset, int len) throws SAXException"
    function is reading the data i was wondering if anybody else had encountered this problem or please let me know if i need to change something in the code: here's a part of the code :
    Bascially i have created three classes to enter data into three mysql tables and as i parse the data i fill up the columns by matching the column header with the tagName.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.*;
    import java.io.*;
    import java.util.ArrayList;
    import java.lang.Object;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import java.util.*;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    public class Echo03 extends DefaultHandler
    StringBuffer textBuffer;
    int issuedValue, prodValue;
    OrdHeader header = new OrdHeader();
    OrdDetail detail = new OrdDetail();
    Member memInfo = new Member();
    //new addition to store the dynamic value of the products
    TestOrdheader prod = new TestOrdheader();
    int counter;
    String tag, newTag;
    SetValue setVal = new SetValue();
    String test;
    public static void main(String argv[])
    if (argv.length != 1) {
    System.err.println("Usage: cmd filename");
    System.exit(1);
    // Use an instance of ourselves as the SAX event handler
    DefaultHandler handler = new Echo03();
    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
    // Set up output stream
    out = new OutputStreamWriter(System.out, "UTF8");
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse( new File(argv[0]), handler);
    } catch (Throwable t) {
    t.printStackTrace();
    System.exit(0);
    static private Writer out;
    private String indentString = " "; // Amount to indent
    private int indentLevel = 0;
    //===========================================================
    // SAX DocumentHandler methods
    //===========================================================
    public void startDocument()
    throws SAXException
    nl();
    nl();
    emit("START DOCUMENT");
    nl();
    emit("<?xml version='1.0' encoding='UTF-8'?>");
    header.assign();
    public void endDocument()
    throws SAXException
    nl(); emit("END DOCUMENT");
    try {
    nl();
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void startElement(String namespaceURI,
    String lName, // local name
    String qName, // qualified name
    Attributes attrs)
    throws SAXException
    indentLevel++;
    nl(); //emit("ELEMENT: ");
    String eName = lName; // element name
    if ("".equals(eName)) eName = qName; // namespaceAware = false
    if (qName.equals("Billing")){
    issuedValue = 1;
    }else if (qName.equals("Shipping")){
    issuedValue = 2;
    }else if (qName.equals("ShippingTotal")){
    issuedValue = 3;
    //check to see if "Product" is the name of the element thats coming next
    if (qName.equals("Product")){
    if (issuedValue != 3){
    prodValue = 1;
    prod.addCounter();
    }else{
    prodValue = 0;
    tag = eName;
    if (attrs != null) {
    for (int i = 0; i < attrs.getLength(); i++) {
    String aName = attrs.getLocalName(i); // Attr name
    if ("".equals(aName)) aName = attrs.getQName(i);
    nl();
    emit(" ATTR: ");
    emit(aName);
    emit("\t\"");
    emit(attrs.getValue(i));
    emit("\"");
    if (attrs.getLength() > 0) nl();
    public void endElement(String namespaceURI,
    String sName, // simple name
    String qName // qualified name
    throws SAXException
    nl();
    String eName = sName; // element name
    if ("".equals(eName)){
    eName = qName; // not namespaceAware
    if ("Order".equals(eName)){          
    //enter into database
         databaseEnter();
    textBuffer = null;
    indentLevel--;
    public void characters(char buf[], int offset, int len)
    throws SAXException
    nl();
    try {
    String s = new String(buf, offset, len);
    if (!s.trim().equals("")){
    settag(tag, s);
    s = null;
    }catch (NullPointerException E){
    System.out.println("Null pointer Exception:"+E);
    //===========================================================
    // Utility Methods ...
    //===========================================================
    // Wrap I/O exceptions in SAX exceptions, to
    // suit handler signature requirements
    private void emit(String s)
    throws SAXException
    try {
    out.write(s);
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    // Start a new line
    // and indent the next line appropriately
    private void nl()
    throws SAXException
    String lineEnd = System.getProperty("line.separator");
    try {
    out.write(lineEnd);
    for (int i=0; i < indentLevel; i++) out.write(indentString);
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    ===================================================================
    ///User defined methods
    ===================================================================
    private String strsplit(String splitstr){
    String delimiter = new String("=");
    String[] value = splitstr.split(delimiter);
    value[1] = value[1].replace(':', ' ');
    return value[1];
    public void settag(String tag, String s){         
    String pp_transid = null, pp_respmsg = null,pp_authid = null, pp_avs = null, pp_avszip = null;
    if ((tag.equals("OrderDate")) || (tag.equals("OrderProcessingInfo"))){
    if (tag.equals("OrderDate")){
    StringTokenizer st = new StringTokenizer(s);
    String orddate = st.nextToken();
    String ordtime = st.nextToken();
    header.put("ordDate", orddate);
    header.put("ordTime", ordtime);
    }else if (tag.equals("OrderProcessingInfo")){
    StringTokenizer st1 = new StringTokenizer(s);
    int tokenCount = 1;
    while (tokenCount <= st1.countTokens()){
    switch(tokenCount){
    case 1:
    String extra = st1.nextToken();
    break;
    case 2:
    String Opp_transid = st1.nextToken();
    pp_transid = strsplit(Opp_transid);
    break;
    case 3:
    String Opp_respmsg = st1.nextToken();
    pp_respmsg = strsplit(Opp_respmsg);
    break;
    case 4:
    String Opp_authid = st1.nextToken();
    pp_authid = strsplit(Opp_authid);
    break;
    case 5:
    String Opp_avs = st1.nextToken();
    pp_avs = strsplit(Opp_avs);
    break;
    case 6:
    String Opp_avszip = st1.nextToken();
    pp_avszip = strsplit(Opp_avszip);
    break;
    tokenCount++;
    header.put("pp_transid", pp_transid);
    header.put("pp_respmsg", pp_respmsg);
    header.put("pp_authid", pp_authid);
    header.put("pp_avs", pp_avs);
    header.put("pp_avszip", pp_avszip);
    }else{
    newTag = new String(setVal.set_name(tag, issuedValue));
    header.put(newTag, s);
    //detail.put(newTag, s);
    prod.put(newTag, s);
    memInfo.put(newTag,s);
    //Check to see-- if we should add this product to the database or not
    boolean check = prod.checkValid(newTag, prodValue);
    if (check){
    prod.addValues(s);
    setVal.clearMod();
    ==================================================================
    Here's the error that i get:
    java.util.NoSuchElementException
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
    at Echo03.main(Echo03.java:47)

    I haven't gone through your code but I also had a similar error....and the exception in my was because of an "&" instead of the entity reference & in one of the element values. I use a non-validating parser but if you use a validating one then this might not be the reason for your exception.

  • XML to CSV using SAX Parser

    Hello
    I need to convert xml files to csv format using SAX Parser. The following code & outputs are as below:
    XML file:
    <Library>
    <Book>
         <Title>Professional JINI</Title>
         <Author>bs</Author>
         <Publisher>Oreilly Publications</Publisher>
    </Book>
    <Book>
         <Title>XML Programming</Title>
         <Author>java</Author>
         <Publisher>Mann Publications</Publisher>
    </Book>
    </Library>
    public class BooksLibrary extends DefaultHandler
    protected static final String XML_FILE_NAME = "C:\\library1.xml";
         public static void main (String argv [])
              // Use the default (non-validating) parser
              SAXParserFactory factory = SAXParserFactory.newInstance();
              try {
                   FileOutputStream fos=new FileOutputStream("C:/test.txt");
                   // Set up output stream
                   out = new OutputStreamWriter (fos, "UTF8");
                   // Parse the input
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );
              } catch (Throwable t) {
                   t.printStackTrace ();
              System.exit (0);
         static private Writer out;
         //===========================================================
         // Methods in SAX DocumentHandler
         //===========================================================
         public void startDocument ()
         throws SAXException
              showData ("<?xml version='1.0' encoding='UTF-8'?>");
              newLine();
         public void endDocument ()
         throws SAXException
              try {
                   newLine();
                   out.flush ();
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
         public void startElement (String name, Attributes attrs)
         throws SAXException
              showData ("<"+name);
              if (attrs != null) {
                   for (int i = 0; i < attrs.getLength (); i++) {
                        showData (" ");
                        showData (attrs.getLocalName(i)+"=\""+attrs.getValue (i)+"\"");
              showData (">");
         public void endElement (String name)
         throws SAXException
              showData ("</"+name+">");
         public void characters (char buf [], int offset, int len)
         throws SAXException
              String s = new String(buf, offset, len);
              showData (s);
         //===========================================================
         // Helpers Methods
         //===========================================================
         // Wrap I/O exceptions in SAX exceptions, to
         // suit handler signature requirements
         private void showData (String s)
         throws SAXException
              try {
                   out.write (s);
                   out.flush ();
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
         // Start a new line
         private void newLine ()
         throws SAXException
              //String lineEnd = System.getProperty("line.separator");
              try {
                   out.write (", ");
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
    --------------------------------------------------------------------------------------------------output is as follows:
    <?xml version='1.0' encoding='UTF-8'?>,
         Professional JINI
         bs
         Oreilly Publications
         XML Programming
         java
         Mann Publications
    Can anyone please tell me how to remove that indentation space & get the output as :
    <?xml version='1.0' encoding='UTF-8'?>, Professional JINI, bs, Oreilly Publications, XML Programming, java, Mann Publications
    Thanks

    By the way, there is a new feature in Java 5.0 (Tiger) called "Annotations."
    Since your code extneds DefaultHandler, you could specify a line with
    @Override
    before the definition of each of your methods. If you had used these, the compiler would have given an error since your methods did not override the methods of DefaultHandler.
    (If your code implemented ContentHandler, by contrast, using @Override is invalid because you need to implement all of the methods defined in the interface definition.)
    The other comment is that the safest way to handle characters() data is to use a StringBuilder/Buffer (StringBuilder is only valid in 5.0, StringBuffer has been around since Release 1.0) that you define in the startElement method. Use the append method to gather data presented to you in the characters() method and use toString() to harvest the data in the endElement method.
    Dave Patterson

  • SAX Parser XML Validation Problems

    Hi,
    I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
    When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
    Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
    Code Snippet:
    boolean isValid = false;
    try {
         // Create and configure factory
    SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    // To be notified of validation errors in the XML document,
    // add a custom error handler to the document builder
    PIMSFeedFileValidationHandler handler
    = new PIMSFeedFileValidationHandler();
         // Create and Configure Parser
    SAXParser parser = factory.newSAXParser();
    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
         // Set reader with entityResolver for dtd
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
    // convert file to URL, as it is a remote file
    URL url = super.getFile().toURL();
    // Open an input stream and parse
    InputStream is = url.openStream();
    xmlReader.setErrorHandler(handler);
    xmlReader.parse(new InputSource(is));
    is.close();
    // get the result of parsing the document by checking the
    // errorhandler's isValid property
    isValid = handler.isValid();
    if (!isValid) {
    LOGGER.warn(handler.getMessage());
    LOGGER.debug("XML file is valid XML? " + isValid);
    } catch (ParserConfigurationException e) {
    LOGGER.error("Error parsing file", e);
    } catch (SAXException e) {
    LOGGER.error("Error parsing file", e);
    } catch (IOException e) {
    throw new FeedException(e);
    return isValid;
    See stack trace below for a little more info.
    2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
    2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
    VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
    org.xml.sax.SAXParseException: Element type "Session" must be declared.
    org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
    org.xml.sax.SAXParseException: Element type "Volume" must be declared.
    org.xml.sax.SAXParseException: Element type "Written" must be declared.
    org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
    org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
    … continues for all the elements in the doc
    2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
    2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
    Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
    Thanks in Advance
    Adam

    Hi David,
    I have checked the ejb-jar.xml file and there is no duplicate values in it and the other things is that the same application is been deployed on OAS 10G and websphere and its working fine. In the forum someone has replied to a similar problem that there is bug in Weblogic 10.3 and its CR no 376292. I am not sure about it, does anyone any information about it.
    Thanks and Regards
    Deepak Dani

  • SAX Parser throws NullPointerException

    Hi.
    I'm using WLS6.1 SP1 built-in XML SAX parser. The code is like,
    SAXParserFactory factory = SAXParserFactory.newInstance();
    XMLReader parser = factory.newSAXParser().getXMLReader();
    // Add a error handler
    eh = new MyErrorHandler();
    parser.setErrorHandler(eh);
    parser.setContentHandler(this);
    // Enable namespace
    parser.setFeature("http://xml.org/sax/features/namespaces", true);
    // Enable validation
    parser.setFeature("http://xml.org/sax/features/validation", false);
    parser.parse(new InputSource(in));
    The NullPointerException is thrown at -
    org.apache.xerces.framework.XMLParser.parse(XMLParser.java:965)
    after the end element of (</eb:MessageHeader>) before the start element of <SOAP-ENV:Header>.
    The XML file is attached.
    =====================================
    However, I tried to parse this document on xerces parser 131.
    It worked fine.
    =====================================
    Did I miss any thing? It seems like a bug to me.
    Thanks!
    [header.xml]

    SAX should mask the fact that some content is specified inside of a CDATA section.. It is just characters.
    The safest way to process characters is to setup a StringBuffer or equivalent in the startElement method. There is a variation of the StringBuffer append method that has the same three parameters (char[], int, int) as the characters signature. The characters method may be called many times before you are given all of the content of the string. How it decides when to call you depends on the parser and is subject to change over time. But, if you accumulate the contents in each call of characters and do the toString() in the endElement method you are going to get the right content. Lots of people over the last year or so that I've been involved in this forum have had other ways they thought were better than this, but most of them have eventually tried and accepted this way because it works and their "better" way did not.
    It looks like you got the content for the CDATA section (Please refer...).I'm not sure what your problem is.
    Dave Patterson

  • Error in SAX Parsing

    Hi Team,
    I am facing an issue while implementing a java mapping through SAX parsing.I am explaining it in details:
    Source Structure   
    =================
    MT_OB_SAX_MAP
    >NUMBER1
    >NUMBER2
    Target Structure
    ==================
    MT_IB_SAX_MAP
    >ADD
    >MUL
    >SUB
    The code that has been written to achieve this is:
    //import java.io.FileInputStream;
    //import java.io.FileOutputStream;
    import com.sap.aii.mapping.api.StreamTransformation;
    import java.io.*;
    import java.util.Map;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class saxmapfinal1 extends DefaultHandler implements StreamTransformation
    private Map map;
    private OutputStream out;
    private boolean input1 = false;
    private boolean input2 = false;
    private int number1;
    private int number2;
    private int addvalue;
    private int mulvalue;
    private int subvalue;
    String lineEnd =  System.getProperty("line.separator");
    public void setParameter (Map param)
    map = param;
    public void execute (InputStream in, OutputStream out)
    throws com.sap.aii.mapping.api.StreamTransformationException
    DefaultHandler handler = this;
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
          SAXParser saxParser = factory.newSAXParser();
          this.out = out;
          saxParser.parse(in, handler);
    catch (Throwable t)
    t.printStackTrace();
    private void write (String s) throws SAXException{
    try{
    out.write(s.getBytes());
    out.flush();
    catch (IOException e){
    throw new SAXException("I/O error", e);
    public void startDocument () throws SAXException{
    write("<?xml version=1.0 encoding=UTF-8?>");
    write(lineEnd);
    write("<ns0:MT_IB_SAX_MAP xmlns:ns0=urn:bp:xi:hr:edm:test:100>");
    write(lineEnd);
    public void endDocument () throws SAXException
    write("</ns0:MT_IB_SAX_MAP>");
    try { out.flush();
    catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void startElement (String namespaceURI, String sName, String qName,Attributes attrs)  
    throws SAXException {
    String eName = sName;
    if ("".equals(eName))
    eName = qName;
    if(eName.equals("NUMBER1"))
    input1 = true;
    if(eName.equals("NUMBER2"))
    input2 = true;             
    public void endElement (String namespaceURI, String sName, String qName) throws SAXException {
    String eName = sName;
    if ("".equals(eName))
    eName = qName;
    if(eName.equals("NUMBER1"))
    input1 = false;
    if(eName.equals("NUMBER2"))
    input2 = false;
    public void characters(char[] chars,int startIndex, int endIndex) throws SAXException
    String dataString =
    new String(chars, startIndex, endIndex).trim();
    if (input1) {
    try
    number1 = Integer.parseInt(dataString);
    } catch(NumberFormatException nfe)
    if (input2) {
    number2 = Integer.parseInt(dataString);
    if (input2 == true)
    addvalue = number1 + number2;
    mulvalue =  number1 * number2;
    subvalue = number1 - number2;
    write("<ADD>" + addvalue +"</ADD>");
    write(lineEnd);
    write("<MUL>" + mulvalue +"</MUL>");
    write(lineEnd);
    write("<SUB>" + subvalue +"</SUB>");
    write(lineEnd);
    But while executing this in XI I am facing an error as "XML not well formed" but I am not able to know why this error is comming.
    Can you please throw some light why this error is happening.?IWhat us the error in the code and what should be the correct code?
    Many thanks for the support that I got in past.
    Regards
    Atanu Mazumdar
    Edited by: ATANU1 on Apr 4, 2011 4:16 PM

    Just use characters() method for building string. Use endElement() to process that string.

  • JAVAMAP-Sax Parser ...............Linkage error when loading the class.

    Dear all,
    Do we have any extra things to execute the Java mapping using the Sax Parser?
    When I am executing the interface mapping ,I am getting the" Linkage error when loading the class" error.
    Kindly let me know your personnel maildId so that I can mail you the screen shots.
    Thanks,
    Srinivasa

    Dear sunil,
    Find the File.
    Source:
    <MTO_FTP_MAT_DETAILS>
    <MATDETAILS>
    <MAKTX>
    <MATNR>
    <WERKS>
    <LABST>
    <MEINS>
    <PERCNT>
    TARGET
    MTI_FTP_MAT_DETAILS
    <MATDETAILS>
    <MAKTX>
    <MATNR>
    <WERKS>
    <LABST>
    <MEINS>
    <PERCNT>
    Source:
    <MTO_FTP_MAT_DETAILS>
    <MATDETAILS>
    <MAKTX>
    <MATNR>
    <WERKS>
    <LABST>
    <MEINS>
    <PERCNT>
    TARGET
    MTI_FTP_MAT_DETAILS
    <MATDETAILS>
    <MAKTX>
    <MATNR>
    <WERKS>
    <LABST>
    <MEINS>
    <PERCNT>
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    import com.sap.aii.mapping.api.StreamTransformation;
    class Echo {
    public static OutputStream out;
    public class myEcho extends DefaultHandler implements StreamTransformation {
    private Map map;
    public void setParameter(Map param) {
    map = param;
    public void execute(InputStream in, OutputStream out) {
    DefaultHandler handler = this;
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
    SAXParser saxParser = factory.newSAXParser();
    Echo.out = out;
    saxParser.parse(in, handler);
    } catch (Throwable t) {
    t.printStackTrace();
    public void startDocument() throws SAXException {
    try {
    Echo.out.write("<?xml version='1.0' encoding='UTF-8'?>".getBytes());
    } catch (IOException e) {
    e.notify();
    public void endDocument() throws SAXException {
    try {
    Echo.out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void startElement(String namespaceURI, String sName, // simple name
    String qName, // qualified name
    Attributes attrs) throws SAXException {
    String eName = sName; // element name
    if ("".equals(eName))
    eName = qName; // not namespace-aware
    if ("ns0:MTO_SAP_MAT_DETAILS".equals(qName)) {
    try {
    Echo.out.write(("<MTI_FTP_MAT_DETAILS>").getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    } else {
    try {
    Echo.out.write(("<" + qName + ">").getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    public void endElement(String namespaceURI, String sName, // simple name
    String qName // qualified name
    ) throws SAXException {
    String eName = sName; // element name
    if ("".equals(eName))
    eName = qName; // not namespace-aware
    if ("ns0:MTO_SAP_MAT_DETAILS".equals(qName)) {
    try {
    Echo.out.write(("</MTI_FTP_MAT_DETAILS>").getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    } else {
    try {
    Echo.out.write(("</" + qName + ">").getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    public void characters(char buf[], int offset, int len)
    throws SAXException {
    String s = new String(buf, offset, len);
    try {
    Echo.out.write(s.getBytes());
    } catch (Exception e) {
    e.printStackTrace();

  • SAX parsing and loops problem

    Hi!
    I currently have an XML file which looks like this:
    <jel>
    <admin creation="Fri Nov 09 17:14:55 GMT 2007" xsdversion="1.0.0" version="1.0.0"/>
    &#8722;
         <jelclass superclass="Object" visibility="public" package="" superclassfulltype="java.lang.Object" fulltype="Player" type="Player">
    &#8722;
         <implements>
    <interface fulltype="java.awt.event.ActionListener" type="ActionListener"/>
    <interface fulltype="java.awt.event.KeyListener" type="KeyListener"/>
    </implements>
    &#8722;
         <methods>
    &#8722;
         <constructor visibility="public" name="Player">
    &#8722;
         <params>
    <param name="newProtocol" fulltype="NewProtocol" type="NewProtocol"/>
    <param name="x" fulltype="int" type="int"/>
    <param name="y" fulltype="int" type="int"/>
    </params>
    </constructor>
    &#8722;
         <method visibility="public" name="actionPerformed" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.ActionEvent" type="ActionEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyPressed" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyReleased" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyTyped" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    <method visibility="public" name="getX" fulltype="int" type="int"/>
    &#8722;
         <method visibility="public" name="setX" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="x" fulltype="int" type="int"/>
    </params>
    </method>
    <method visibility="public" name="getY" fulltype="int" type="int"/>
    &#8722;
         <method visibility="public" name="setY" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="y" fulltype="int" type="int"/>
    </params>
    </method>
    </methods>
    </jelclass>And I have SAX parsing code that looks like this:
    public class SaxParser{
          private HashSet <String>packageSet = new HashSet<String>();
          private ArrayList <String> classList = new ArrayList<String>();
          private ArrayList <String> packageList = new ArrayList<String>();
          private ArrayList <String> methodList = new ArrayList<String>();
          private Object[] packageNames;
          private HashMap <String, ArrayList> h = new HashMap <String, ArrayList>();
          public SaxParser()throws Exception{
              String fname = "eclipse/jel.xml";
             DefaultHandler handler = new DefaultHandler()
                 private int numberOfClasses = 0;
             public void startElement(String namespaceURI,String localName, String qname, Attributes attrs)
                  if(qname.equals("jelclass")) {
                       numberOfClasses ++;
                  for(int i = 0; i< attrs.getLength();i++){
                        if(attrs.getQName(i).equals("type")){
                             classList.add(attrs.getValue(i));
                             if(attrs.getQName(i).equals("package")){
                                  packageList.add(attrs.getValue(i));
                                  packageSet.add(attrs.getValue(i));
                  for(int i = 0; i< attrs.getLength();i++){
                       for(int j = 0; j < classList.size(); j++){
              if(attrs.getQName(i).equals("type") && attrs.getValue(i).equals(classList.get(j))){
                  if(qname.equals("method")){
                        if(attrs.getQName(i).equals("name")){
                                    h.put(classList.get(i), methodList.add(attrs.getValue(i));
                   packageNames = new String[packageSet.size()];
                  packageNames = packageSet.toArray();
             public void endElement(String namespaceURI,String localName, String qname){}};
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(new File(fname), handler);
         public int getPackageNumber(){
              return packageSet.size();
         public Object[] getPackageNames(){
              return packageNames;
         public ArrayList getPackageList(){
              return packageList;
         public ArrayList getClassList(){
              return classList;
         public ArrayList getMethodList(){
              return methodList;
          public static void main(String[] args)throws Exception{
               new SaxParser();
    }I am currently pulling out the package names, pulling out the classnames and then mapping these in a separate class - this works because the class and package names are declared in the same line, so if a package name appears in the package list 7 times, i know this package has 7 classes, and therefore i count the first 7 classes out of an array of all the classes and know that these are the right 7 for that package. However, the methods are a bit different:
    What I would like to do is to: for every class make a hashmap which maps the class name onto an arraylist of the methods, but i think i'm getting confused with my for loops. Or even just keep a tally of how many methods each class has, then I can work it out as i did with the packages -> classes.
    Does anyone know where im going wrong, or have any ideas at all?
    Thank you for your time,
    beccy
    :)

    I don't know if stacks are specifically mentioned in any SAX documentation.
    Basically, SAX sends you a stream of XML elements (open and close tags, characters, etc.), but it doesn't know anything about the underlying XML structure. You have to add that part (usually -- sometimes when writing a SAX application, you don't really care about the XML structure). XML structure is a tree.
    If you've ever written a recursive function that spans a tree, you'll have an idea what to do. You can use a stack to keep track of where you are in the tree. For example, if you open tag A, then you're "in" the A element for subsequent content in that document; if you then open tag B, you're in the B element; but when you close the B tag, you need the stack to tell you that now you're back in the A element.
    You may not need stacks, but it's likely. Find a good tutorial about SAX that mentions stacks and you'll be fine.
    Edited by: paulcw on Nov 14, 2007 4:09 PM

  • SAX Parser in Webdynpro for Java

    Hi,
         Scenario : To get data entered in the Dynamic table of an online PDF form.
    I have got the XML of the PDF form. The problem is with Parsing the XML to get the data.
    I am using SAX parser. The code structure is as given,
    public class Outercomp
        getPDFData(IS);    // IS is the Inputstream of the PDF XML
       // begin Others
       public static class inner extends DefaultHandler
            void getPDFData(InputStream IS)
                  SAXParserFactory SAXfac = SAXParserFactory.newInstance();
                  SAXParser SAX = SAXfac.newSAXParser();
                  SAX.parse(IS, new Outer.Inner());
            void startElement()
                 // some Code
    Problem :
    I am getting the below exception at calling the method 'parse'.
    com.sap.engine.lib.xml.parser.NestedSAXParserException: Generic Exception: -> java.lang.NullPointerexception
    I checked both 'IS' and 'new Outer.Inner()', both are not null.
    Please give me a solution
    Thanks,
    Prabhakar

    Hi Satyajit,
         ' DefaultHandler ' is a class, and I am extending it.
         First I missed it in the code, now I have changed it. Thanks for reminding me.
    Thanks,
    Prabhakar

  • Sax Parser for loading XML file

    We have a requirment by which we need to load huge XMl file in our DB everyday.
    THe XML file format is like --
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <emp>
    <ename>aaa</ename>
    <sal>3000</sal>
    </emp>
    <emp>
    <ename>bbb</ename>
    <sal>5000</sal>
    </emp>
    <dept>
    <name>productiong</name>
    <location>USA</location>
    <dept>
    I have written XMl SAX parser to load this file into DB -
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.XMLReader;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.Attributes;
    import java.io.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.pool.OracleDataSource;
    import java.util.*;
    public class test extends DefaultHandler
    String thisElement="";
    String table_name="";
    String table_name_2="";
    String sql="";
    String value_clause="";
    StringBuffer value_clauseBuffer;
    String Insert_sql="";
    int flag;
    String columnNames="";
    String questionmarks="";
    static String conStr = "jdbc:oracle:thin:@abcd1234:1521:dss501";
    static Connection conn;
    String arrayValues[] = new String[30];
    int j = 0;
    int emptyElementFlag = 0;
    public SurveyReader() throws SQLException, FileNotFoundException, IOException{
    DBConnect("username", "password");
    public static void DBConnect(String username, String password)
    throws SQLException, FileNotFoundException, IOException {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(conStr, username, password);
    conn.setAutoCommit(true);
    public void startElement(String namespaceURI, String localName,
    String qName, Attributes atts) throws SAXException {
    thisElement = qName;
    if (thisElement!=table_name){
    columnNames = columnNames + ", " + qName;
    questionmarks = questionmarks +", " + "?";
    emptyElementFlag =0;
    public void characters(char[] ch, int start, int length)
    throws SAXException {
    if (thisElement !="root"){     
    if ((length == 0) && (thisElement !="") ){
    table_name = thisElement;
    sql = " Insert into "+ table_name +"(";
    value_clause="";
    value_clauseBuffer =null;
    columnNames = "";
    questionmarks ="";
    j =0;
    if ((length != 0) && (thisElement!="") && (thisElement!=table_name)){
    emptyElementFlag = 1;
    String s = new String(ch, start, length);
    String newString = s.replaceAll("'", "''");
    // String newString = s;
    if (value_clauseBuffer== null){
    value_clauseBuffer = new StringBuffer(newString);
    else{
    value_clauseBuffer.append(newString);
    public void endElement(String namespaceURI, String localName, String qName)
    throws SAXException {
    if (thisElement !="root"){
    if ((!(value_clauseBuffer == null))||((emptyElementFlag ==0) && (qName !=table_name))) {
    try{
    //value_clauseBuffer.append("', '");
    if (value_clauseBuffer == null){
    arrayValues[j]="";
    else{
    arrayValues[j]=""+value_clauseBuffer;
    j = j+1;
    value_clauseBuffer = null;
    emptyElementFlag =0;
    }catch(Exception e){
    System.err.println(e);
    System.exit(2);
    if (qName == table_name){
    if (!(value_clauseBuffer == null)){
    value_clause = "'"+value_clauseBuffer;
    columnNames =columnNames.substring(1, columnNames.length());
    int paramNumber = j;
    questionmarks =questionmarks.substring(1, questionmarks.length());
    sql = sql + columnNames + " ) values (" + questionmarks +"); ";
    Insert_sql=Insert_sql + sql;
    sql = "Begin "+sql + " End; ";
         try{
         PreparedStatement pstat = conn.prepareStatement(sql);
    for (int i=0; i<=j-1; i++ ){
    int k = i+1;
    pstat.setObject(k, arrayValues);
         ResultSet rset = pstat.executeQuery();
         rset.close();
         pstat.close();
    catch (Exception e) {
    System.err.println(e);
    System.out.print("sql " + sql);
    System.exit(1);
    table_name_2 = table_name;
    thisElement = "";
    public static void main (String args[]) {
    XMLReader xmlReader = null;
    System.out.println("Time " + new java.util.Date());
    try {
    SAXParserFactory spfactory = SAXParserFactory.newInstance();
    spfactory.setValidating(false);
    SAXParser saxParser = spfactory.newSAXParser();
    xmlReader = saxParser.getXMLReader();
    xmlReader.setContentHandler(new SurveyReader());
    xmlReader.setErrorHandler(new SurveyReader());
    InputSource source = new InputSource("short.xml");
    xmlReader.parse(source);
    conn.close();
    } catch (Exception e) {
    System.err.println(e);
    System.exit(1);
    This parser takes 2 hours to laod file of size around 8MB.
    ANy suggestions on improving performance of the parser.
    ANy other approach I should be taking to load this file into DB.
    We are using ORacle 9i DB with Character set UTF 8.
    Thanks!

    String buf = (new String(ch, start, length)).trim();
    if (thisElement != "root"){   
    if ((buf.length() == 0) && (thisElement !="") ){
    It run ok!
    Thanks 58871!
    Now, i want to export oracle table to xml file like :
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <emp>
    <ename>aaa</ename>
    <sal>3000</sal>
    </emp>
    <emp>
    <ename>bbb</ename>
    <sal>5000</sal>
    </emp>
    </root>
    Can SAX export to xml format?
    Pham Thanh Tung

  • SAX Parser in OC4J

    I'm trying to read a XML file in an EJB using a SAX parser.
    I tried the following statement to create the reader
    XMLReader xr = XMLReaderFactory.createXMLReader("oracle.xml.parser.v2.SAXParser");
    but I obtain the following exception:
    java.lang.ClassNotFoundException: oracle.xml.parser.v2.SAXParser
    at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:118)
    The same works correctly from a command line application outside OC4J.
    Is there another SAX Parser I can use in OC4J?
    Andrea Mattioli

    I'm also seeing the a similar problem trying to get my EJB to parse SAX using the Xerces parser. If I do
    XMLReader myReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    and place xerces.jar into $(OC4J_INSTALL_ROOT)\j2ee\home\lib then at runtime I get
    java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
    This is despite the fact that calling Class.forName() on the same class name works fine. Setting the system property org.xml.sax.driver and calling createXMLReader with no parameters results in the same error.
    I can force use of the Xerces SAX parser by bypassing the factory and just calling
    XMLReader myReader = new org.apache.xerces.parsers.SAXParser();
    but that seems a tad hacky and I don't want to hardwire SAX parser implementation choice into my code.
    Is this a known bug?
    Also which parser is getting used by default in OC4J i.e. if I don't set org.xml.sax.driver and use the no parameters variant of createXMLReader()?
    Thanks
    Alan

  • Sax parser problem plz help

    hi !!!!!!!!!!!!
    Im using a SAX parser to parse an xml file im successful in doing it i got tit parse after parising i want the value of a particular tag for example i have a tag as
    <filtername>datasource</filtername>
    i want datasource after parsing the xml and without using DOM concept how do i do it please help

    hi i have a parser for start parsing and for start element
    when im doing this i get the complete xml parsed after the xml is parsed how do i get it i still could not get how to soak the characters .....
    private void startParsing()
              try
                   InputStream instream = getClass().getClassLoader().getResourceAsStream(contextFile);
                   InputSource in = new InputSource(instream);
                   SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                   XMLReader reader = parser.getXMLReader();
                   reader.setContentHandler(this);
                   reader.parse(in);
              catch(ParserConfigurationException pce)
                   System.out.println(pce);
              catch(SAXException se)
                   System.out.println(se);
              catch(IOException ie)
                   System.out.println(ie);
         public void startElement(String uri,String localName,String qName,Attributes attributes)
              System.out.format("uri : %s localName %s qName %s %n",uri,localName,qName);
    so now i have an attribut but i need content of the opening and closingtag like
    attribute is name
    <name>jack</name>
    im successfull in getting name but now i want jill ....

  • How to Feed HTTP POST reply to a SAX Parser?

    Hello
    I want to make a POST, the body of the reply is an xml document I want to parse it with help of a SAX parser (responseHandler object here). I have not been able to setup a test environment and I have limited time so I wanted to check with you if you have any remarks on my code, or if you better solution. I have done the following
    URL url = new URL("http://myserver.com:8888");
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("POST");
                connection.setAllowUserInteraction(false);
                connection.setDoOutput(true);
                connection.setRequestProperty("Content-type",
                        "application/x-www-form-urlencoded");
                connection.setRequestProperty("Content-length", Integer
                        .toString(content.length()));
            OutputStream ost = connection.getOutputStream();
            PrintWriter pw = new PrintWriter(ost);
            pw.print(content);// send
            pw.flush();
           httpReply = connection.getResponseCode();
                // could not contact server
                if (httpReply != HttpURLConnection.HTTP_OK) {
                    // TODO Check for thread safety
                    alarmHandler.raiseServerNotAvailableAlarm();
                    result = new String[0];
                    return result;
                    // Contacted Server
                   // now parse the reply
                } else {
                    alarmHandler.clearServerNotAvailableAlarm();
                    SAXParserFactory spf = SAXParserFactory.newInstance();
                    SAXParser parser = spf.newSAXParser();
                    parser.parse(connection.getInputStream(), responseHandler);
                    return (String[]) responseHandler.getRejectedMSISDNs().toArray();
                }Edited by: keyhan on Jun 19, 2008 4:06 AM

    Hello
    I want to make a POST, the body of the reply is an xml document I want to parse it with help of a SAX parser (responseHandler object here). I have not been able to setup a test environment and I have limited time so I wanted to check with you if you have any remarks on my code, or if you better solution. I have done the following
    URL url = new URL("http://myserver.com:8888");
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("POST");
                connection.setAllowUserInteraction(false);
                connection.setDoOutput(true);
                connection.setRequestProperty("Content-type",
                        "application/x-www-form-urlencoded");
                connection.setRequestProperty("Content-length", Integer
                        .toString(content.length()));
            OutputStream ost = connection.getOutputStream();
            PrintWriter pw = new PrintWriter(ost);
            pw.print(content);// send
            pw.flush();
           httpReply = connection.getResponseCode();
                // could not contact server
                if (httpReply != HttpURLConnection.HTTP_OK) {
                    // TODO Check for thread safety
                    alarmHandler.raiseServerNotAvailableAlarm();
                    result = new String[0];
                    return result;
                    // Contacted Server
                   // now parse the reply
                } else {
                    alarmHandler.clearServerNotAvailableAlarm();
                    SAXParserFactory spf = SAXParserFactory.newInstance();
                    SAXParser parser = spf.newSAXParser();
                    parser.parse(connection.getInputStream(), responseHandler);
                    return (String[]) responseHandler.getRejectedMSISDNs().toArray();
                }Edited by: keyhan on Jun 19, 2008 4:06 AM

Maybe you are looking for

  • Is there any way to customize a repeat event in iCal on my iPad?

    On my old MacBook, I was able to customize a repeat event, I.e., plan a recurring event for the first Thursday of every month, as opposed to the first of every month. I am attempting to switch to my new iPad, and cannot seem to find the function in i

  • How 2 Install Aperture on a new computer

    I just ordered a new Mac Pro. I have Aperture on my old computer and I want to install it on the new one. I don't want to use the Aperture v1.0 CD then do all the updates to get to the latest version. Is there a way to download the latest version of

  • Siri does not work after IOS 7 install

    Siri doesent work after I OS 7 install I hear it is a hardware problem. Siri works fine but then you download IOS seven and it stops working. Apple has told a couple people they have to buy a new phone. I hope thats not true. Because I will buy a new

  • Do I really need ASIO

    I'm running XP with an onboard SoundMax audio card and Audition 3.0.  When I installed and selected ASIO4All the record buttons grey out and cannot be selected.  I seem to be getting decent audio for my crappy radio spots with the Windows drivers but

  • Help with NAS (Network Audio System) setup.

    Anyone having any ideas how to set up this? I couldn't find any documentation, no howtos, no help, just an obscure nasd.con.eg in the package. Has anyone managed to set up a client and a server for this system, it'd be really useful to me...