Sax Parser application

I have a Sax Parser Application which is working fine for parsing file with paths from D: or O: or N:
Also I have the rights to access C: , but it gives me a following error when I access from C:
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at ProcessServlets.fileparser(ProcessServlets.java:47)
at ProcessServlets.doGet(ProcessServlets.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
Edited by: Siddhesh77 on Jan 29, 2010 9:51 AM

Siddhesh77 wrote:
I have a Sax Parser Application which is working fine for parsing file with paths from D: or O: or N:
Also I have the rights to access C: , but it gives me a following error when I access from C:
java.net.MalformedURLException: unknown protocol: cThe exception says the URL you are providing is malformed.
If you have any automatic file URL creation mechanism then check it first weather it is creating malformed URLs. I'll suggest to test your program with some static URL's.
Please provide file URL's which are working and which are not working.

Similar Messages

  • How to deal with empty tags in a SAX Parser

    Hi,
    I hope someone can help me with the problem I am having!
    Basically, I have written an xml-editor application. When an XML file is selected, I parse the file with a SAX parser and save the start and end locations of all the tags and character data. This enables me to display the xml file with the tags all nicely formatted with pretty colours. Truly it is a Joy To Behold. However, I have a problem with tags in this form:
    <package name="boo"/>
    because the SAX parser treats them like this:
    <package name = boo>
    </package>
    for various complex reasons the latter is unaccetable so my question is: Is there some fiendishly clever method to detect tags of this type as they occur, so that I can treat them accordingly?
    Thanks,
    Chris

    I have spent some time on googling for code doing this, but found nothing better, than I had to write in by myself.
    So, it would be something like this. Enjoy :)
    package comd;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.SAXException;
    import org.xml.sax.Attributes;
    import java.util.Stack;
    import java.util.Enumeration;
    public class EmptyTagsHandler extends DefaultHandler {
         private StringBuilder xmlBuilder;
         private Stack<XmlElement> elementStack;
         private String processedXml;
         private class XmlElement{
              private String name;
              private boolean isEmpty = true;
              public XmlElement(String name) {
                   this.name = name;
              public void setNotEmpty(){
                   isEmpty = false;
         public EmptyTagsHandler(){
              xmlBuilder = new StringBuilder();
              elementStack = new Stack();
         private String getElementXPath(){
              StringBuilder builder = new StringBuilder();
              for (Enumeration en=elementStack.elements();en.hasMoreElements();){
                   builder.append(en.nextElement());
                   builder.append("/");
              return builder.toString();
         public String getXml(){
              return processedXml;
         public void startDocument() throws SAXException {
              xmlBuilder = new StringBuilder();
              elementStack.clear();
              processedXml = null;
         public void endDocument() throws SAXException {
              processedXml = xmlBuilder.toString();
         public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
              if (!elementStack.empty()) {
                   XmlElement elem = elementStack.peek();
                   elem.setNotEmpty();
              xmlBuilder.append("<");
              xmlBuilder.append(qName);
              for (int i=0; i<attributes.getLength();i++){
                   xmlBuilder.append(" ");
                   xmlBuilder.append(attributes.getQName(i));
                   xmlBuilder.append("=");
                   xmlBuilder.append(attributes.getValue(i));
              xmlBuilder.append(">");
              elementStack.push(new XmlElement(qName));
         public void endElement(String uri, String localName, String qName) throws SAXException {
              XmlElement elem = elementStack.peek();
              if (elem.isEmpty) {
                   xmlBuilder.insert(xmlBuilder.length()-1, "/");
              } else {
                   xmlBuilder.append("</");
                   xmlBuilder.append(qName);
                   xmlBuilder.append(">");
              elementStack.pop();
         public void characters(char ch[], int start, int length) throws SAXException {
              if (!elementStack.empty()) {
                   XmlElement elem = elementStack.peek();
                   elem.setNotEmpty();
              String str = new String(ch, start, length);
              xmlBuilder.append(str);
         public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
              String str = new String(ch, start, length);
              xmlBuilder.append(str);
    }

  • JAVA mapping using SAX parser adds extra tags

    Hi,
      We are using  java mapping using a SAX parser.It works well in standalone application ie it parses correctly and gets our desired xml structure and the xml is well formed too but when we import it in XI as a jar file it does not throw any errors but adds extra start tags, as a result the output xml is not well formed.XI is adding extra start tags.
    If any one else has faced a similar situation please help.
    Regards,
    Anirban.

    Hi Roberto,
    Thank you for the response.
    As I said, it doesnt throw any error. It is working perfectly in standalone application. But when we deploy it to XI Server, it is not forming the well formed XML. We too are puzzled by this situation.
    Okay, i will explain my scenario here.
    The following is my input XML to the java pgm..
    <Header>
    </Header>
    <Body>
    </Body>
    <SubBody1>
    </SubBody1>
    <SubBody2>
    </SubBody2>
    <SubBody3>
    </SubBody3>
    <SubBody4>
    </SubBody4>
    <Trail>
    </Trail>
    The desired output is
    <Header>
      <Body>
         <NameChanged1>
            <NameChanged2>
    <SubBody3>
    <SubBody4>
    </SubBody4>
    </SubBody3>
    </NameChanged2>
    </NameChanged1>
    <Trail>
    </Trail>
    Just look at the SubBody2 and SubBody1 node, its tag name has been changed in the output XML. Thats y i have decided to use java mapping instead of message mapping.
    I have developed the code for everything, i.e for changing the tag name and for forming the nested xml and it is working fine as a standalone application. But while deploying it to XI, the output is not well formed. I dont know the reason for it. Even I have checked the cardinality of the output Data types, that I have created. Its perfectly okay with all.
    Any Ideas???
    Regards,
    Anirban

  • 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 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 is dropping characters

    Hello,
    We have noticed that the BEA implementation of the SAX parser appears
    to drop characters from the start of an attribute's value.
    For example:
    <attribute-value>au.com.bonline.bean.SomeClass</attribute-value>
    becomes
    online.bean.SomeClass
    after parsing.
    Has anyone seen this behaviour before ?
    Previously we were running the application under tomcat and did not have
    this issue with the implementation of the SAX parser that comes with
    tomcat.
    Are there changes we have to make to the way we code against the
    SAX parser that we might have missed moving from tomcat to BEA ?
    Thankyou,
    Brian Gorrie
    Programmer/Analyst
    B Digital

    Hi Brian,
    I just tried this simple program with the output below; it worked OK
    using WLS 8.1
    What WLS version and can you provide a test case?
    Thanks,
    Bruce
    C:\stephens\CRs\crXML>type attr.xml
    <?foo version="1.0" ?>
    <A>
    <attribute-value>au.com.bonline.bean.SomeClass</attribute-value>
    </A>
    C:\stephens\CRs\crXML>java -classpath .;%CLASSPATH% sax attr.xml
    Start document
    Processing Instruction:
    target: foo
    data: version="1.0"
    Start element: A
    Characters: "\n"
    Start element: attribute-value
    Characters: "au.com.bonline.bean.SomeClass"
    End element: attribute-value
    Characters: " \n"
    End element: A
    End document
    Brian Gorrie wrote:
    >
    Hello,
    We have noticed that the BEA implementation of the SAX parser appears
    to drop characters from the start of an attribute's value.
    For example:
    <attribute-value>au.com.bonline.bean.SomeClass</attribute-value>
    becomes
    online.bean.SomeClass
    after parsing.
    Has anyone seen this behaviour before ?
    Previously we were running the application under tomcat and did not have
    this issue with the implementation of the SAX parser that comes with
    tomcat.
    Are there changes we have to make to the way we code against the
    SAX parser that we might have missed moving from tomcat to BEA ?
    Thankyou,
    Brian Gorrie
    Programmer/Analyst
    B Digital[sax.java]

  • SAX-parser and mapping on the XI

    Helllo everybody,
    I'm trying to map an xml-document using the SAX-parser.
    I'm reading the data using an impustream. the problem is, while testing on the XI, the following message comes :
    Creating Java mapping xmlDataExchangeSAPSample/XMLValidation
    Loaded class xmlDataExchangeSAPSample.XMLValidation
    Loaded class xmlDataExchangeSAPSample.myErrorHandler
    Call method execute of the application Java mapping xmlDataExchangeSAPSample.XMLValidation
    START APPLICATION TRACE ***
    xxx implementierende Klasse Parserscom.sap.engine.lib.jaxp.SAXParserFactoryImpl
    erstelltes Dokument aus in EDIFACTINTERCHANGE
    Beginn Parsenjava.io.ByteArrayInputStream@1aa342a3
    SAXException when parsing Generic Exception:
    com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!
    END APPLICATION TRACE ***
    Java mapping xmlDataExchangeSAPSample/XMLValidation completed. (execute() of xmlDataExchangeSAPSample.XMLValidation
    Ausführung war erfolgreich.
    10:18:14 Testende
    the the Document ist generated :
    "...erstelltes Dokument aus in EDIFACTINTERCHANGE.."
    but the parser find an empty source.
    do you have an idea what could be happening here?
    Kind regards

    Hi,
      <<
    xxx implementierende Klasse Parserscom.sap.engine.lib.jaxp.SAXParserFactoryImpl
    erstelltes Dokument aus in EDIFACTINTERCHANGE
    Beginn Parsenjava.io.ByteArrayInputStream@1aa342a3
    SAXException when parsing Generic Exception:
    com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!
    >>
    This seems that u r trying parse a file rather than valid XML document..
    Usually you will notice this problem when u r trying to parse a payload which is in txt format usually when u r using File Adapter message protocol as "FILE" instead of "FCC".
    Usually SAX is an API Desinged to parse Valid XML Documents only.
    If you want to do manipulations on NON XML data better to use Java.io.InputStream & OutputStream.
    Regards,
    Rao.Mallikarjuna

  • SAX Parser Gotcha

    For what its worth, the Java SAX XML had/has a killer gotcha that one must compensate for or it does not work.
    Essentially, a SAX parser has five routines one has to program:
    startDocument
    startElement
    characters
    endElement
    endDocument
    The characters routine is where the contents of a tag appear.
    Suppose the underlying disk read routine does a read of the
    input stream that does not terminate at a tag; that has to happen
    occasionally. Then all the characters routine will see is part
    of a tag's contents. The next read of the input stream will
    cause characters to be called again with the second half of
    the tag's contents in the buffer. The application has to be
    smart enough to append the second half of the tag's contents
    to the first half, or there will be an error. My solution was
    to initialize a string in startElement, always append to it in
    characters, and call it the contents of the tag in endElement.
    This seems to work for me.
    It took weeks to find and fix this error. And as far as I know
    there is no defense against it, other than the one I outined above.
    I have read several books on XML and have never seen this problem
    described.
    Has anyone else ever seen this problem and have a better soln
    for it?
    Charles Elliott

    From the API documentation for the characters() method of org.xml.sax.ContentHandler:
    The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.You ask if anyone else has ever seen the problem? Actually it's an FAQ in this forum. Appears every couple of weeks. You've found the correct way to handle it. (Although using a StringBuilder instead of a String to accumulate the data might be a tiny bit better.)

  • 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

  • SAX Parser - Decoding request data

    I have implemented the SAX Parser on a web application. To do this I create a BufferedReader from the request and then call the SAX parse() method.
    BufferedReader reader = request.getReader();
    InputSource inputSource = new InputSource( reader );
    xmlReader.parse( inputSource );
    The problem is that when the XML data is posted to our web application the data from the request is encoded, and thus I need to decode it before calling parse().
    Has anyone encountered this problem? If so, what was their solution?

    I'm not sure, but are you posting the XML data as a form field? In that case you need to fetch the string data for the given parameter from the request object using getParameter() and feed that to the XML parser. What you are fetching now is the raw HTTP request data.

  • Encoding error using Oracle SAX Parser, please help

    Hi, All,
    I have problem while I am trying to parse an XML file using Oracle SAX Parser.
    The following is from the trace file:
    java.io.UTFDataFormatException: Invalid UTF8 encoding.
    java.io.UTFDataFormatException: Invalid UTF8 encoding.
    at java.lang.Throwable.&lt;init&gt;(Compiled Code)
    at java.lang.Exception.&lt;init&gt;(Compiled Code)
    at java.io.IOException.&lt;init&gt;(Compiled Code)
    at java.io.UTFDataFormatException.&lt;init&gt;(Compiled Code)
    at oracle.xml.parser.v2.XMLUTF8Reader.checkUTF8Byte(Compiled Code)
    at oracle.xml.parser.v2.XMLUTF8Reader.readUTF8Char(Compiled Code)
    at oracle.xml.parser.v2.XMLUTF8Reader.fillBuffer(Compiled Code)
    at oracle.xml.parser.v2.XMLByteReader.saveBuffer(Compiled Code)
    at oracle.xml.parser.v2.XMLReader.fillBuffer(Compiled Code)
    at oracle.xml.parser.v2.XMLReader.tryRead(Compiled Code)
    at oracle.xml.parser.v2.XMLReader.scanXMLDecl(Compiled Code)
    at oracle.xml.parser.v2.XMLReader.pushXMLReader(Compiled Code)
    at oracle.xml.parser.v2.XMLReader.pushXMLReader(Compiled Code)
    at oracle.xml.parser.v2.XMLParser.parse(Compiled Code)
    at data_loader.main(Compiled Code)
    The XML file is a pure ascii text file, with encoding set to UTF-8.
    I can parse the file correctly on NT, but I got problem when I ran the code on a SUN solaris 2.6 machine.
    The parser version is 9.0.2.
    Thanks in advance.
    Peter

    You are right, I modified the codes and got it to work on Oracle
    But when I did your suggestion:
    <cftransaction>
      <cfstoredproc ...>
      <cfquery>
        SELECT ...
      </cfquery>
    </cftransaction>
    I got the same error as before which is:
    Error Executing Database Query.
    [Macromedia][Oracle JDBC Driver]Unhandled sql type
    But this time it points to the CF callling the str proc using cfprocparam
    Here is how I call the str. proc:
         <CFTRANSACTION>   
              <cfstoredproc procedure="MyReport" datasource="#Trim(application.dsn)#" returncode="True">  
                  <cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="ins_name" value="#Trim(session.instname)#">
                  <cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="aca_year" value="#Trim(ayr)#"> <------- POINT TO THIS LINE
              </cfstoredproc>
         </CFTRANSACTION>

  • IPlanet 6.0 SAX parser fatal error

    I am getting the following error, at the start of iPlanet 6.0 web server. The line number 5 is <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    in the file web.xml
    Error message in iPlanet:
    failure ( 1608): vs(https-CLV-EATON)SAX parser fatal error: External entity not found: "http://java.sun.com/dtd/web-app_2_3.dtd". in file:/c:/iPlanet/Servers/docs/EatonIP/WEB-INF/web.xml at line number 5. [30/Jul/2002:18:25:09] warning ( 1608): vs(https-CLV-EATON)Error parsing web-app deployment descriptor c:\iPlanet\Servers\docs\EatonIP\WEB-INF\web.xml: External entity not found: "http://java.sun.com/dtd/web-app_2_3.dtd".
    Any help is appreciated.

    Hi,
    I'm facing same problem with iPlanet. I want to add <listener> in web.xml file. My web server has web-app_2_2.dtd file. But this file don't have entry for <listener>, then I found that web-app_2_3.dtd has this entry. I have to use this file. I'm using iPlanet 6.
    So please let me know that how I do that ?
    Can I add new DTD file to Web Server ? How ?
    Can I install any patch to have web-app_2_3.dtd file on Web Server ?
    U can send me mail on [email protected]
    This is how my web.xml file is
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <listener>
    <listener-class>CRSSessionListener</listener-class>
    </listener>
    </web-app>
    Whenever I include web-app_2_3.dtd file in web.xml, I'm getting error that 'External entity 'web-app_2_3.dtd' not found. And if I'm not using web-app_2_3.dtd file then web server could not parse web.xml file.
    If u have found the solution can u mail me [email protected]
    Thanx in advance,
    ~Abhijeet

  • 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

  • Disadvantages of SAX parser

    tell me some disadvantages of the SAX parser.

    Hi Sankar
    Disadvantage of SAX are as follows
    1)SAX is an event-driven push model for processing XML. It is not a W3C standard,
    2)Rather than building a tree representation of an entire document as DOM does, a SAX parser fires off a series of events as it reads through the document.
    3)The disadvantage of SAX is that you have to implement the event handlers to handle all incoming events. You must maintain this event state in your application code. Because the SAX parser does not communicate meta-information such as DOM's parent/child
    4) you have to keep track of where the parser is in the document hierarchy. Thus, the more complex your documents are, the more complex your application logic becomes.
    5)Even though there is no need to load the entire document into memory at one time, a SAX parser still needs to parse the whole document, as with DOM.
    6)Probably the biggest problem facing SAX is that it does not have built-in document navigation support such as that provided by XPath. This, coupled with its one-pass parsing, means there is no random access support.
    7)This limitation also shows up in namespaces: Elements that have inherited namespaces will not be annotated. These limitations make SAX a poor choice for manipulating or modifying a document
    SAX (Simple API for XML) it is probably the most complete and accurate method so far.
    This is used for XML  documents.The SAX classes provide an interface between the input streams from which XML documents are read and the client software which receives the data made available by the parser. The parser browses through the whole document and fires events every time it recognizes an XML construct (e.g. it recognizes a start tag and fires an event – the client software is notified and can use this information… or not).
    For more details you can refer to link
    http://www.oracle.com/technology/oramag/oracle/03-sep/o53devxml.html
    hope it may help you
    Thanks
    sandeep
    PS: if helpful reward points

  • Exiting from SAX parser on finding specific element/attribute

    Is there a way to return/exit from a SAX parser as soon as I get my search element the first time, without parsing the whole XML file?
    Please let me know.
    Thanks

    Thanks for the information, but what I am exactly looking for is to only return back from SAX parser to the calling program.
    System.exit(0) shuts down the whole application.
    please let me know

Maybe you are looking for