Regarding DocumentBuilder.parse method returns reference as null value.

Hi
We are in the process of migrating code which works on WebSphere/JBOSS to WLS..
We are using DocumentBuilder object for parsing the Locale related xml data. I understand that the DocumentBuilder is provided by DocumentBuilderFactory which is an interface whose implementation is server specific.
But when the Document Builder parse method is called with a valid file path, we are getting System.Out of doc.getFirstChild().getLocalName() as null (which ideally should have been the name of the first node). No Errors are observed .
For WLS, the parser is giving the document object reference as null whereas in other servers like Websphere and JBOSS we are able to parse the same xml with proper object reference.
Could you please help in this regard?
Thanks and regards
Anil

Hi Vmotamar,
If you think that the parsers available as part of WebLogic are causing the issues, Then you can use your Own Parsers while migrating to WebLogic Server. I mean Get the Parser Jar files which u used as part of JBoss or WebSphere and put it inside the "APP-INF\lib" directory of your EAR Application or Put them inside "WEB-INF\lib" of your WEBApplication...and then Apply ClassLoader Filtering feature provided by WebLogic ...which allows an application to use It's Own Jars\Classes ...
Please refer to: http://forums.oracle.com/forums/thread.jspa?threadID=1109267&tstart=150 and in http://weblogic-wonders.com/weblogic/parsers_issues
Thanks
Jay SenSharma
http://weblogic-wonders.com/weblogic/parsers_issues/ (WebLogic Wonders Are Here)

Similar Messages

  • Make DocumentBuilder.parse ignore DTD references

    Thanks to everyone in advance -
    So this issue looks to be pretty popular, I have found a few solutions, but nothing seems to stop the downloading of dtd files, for instance ones sitting up on w3.org.
    Here are some of the solutions i have found:
    http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
    http://forums.sun.com/thread.jspa?threadID=284209&forumID=34
    When I use this solution:
    myDocumentBuilder.setEntityResolver(new EntityResolver() {
              public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
                     throws SAXException, java.io.IOException
                if (publicId.equals("--myDTDpublicID--"))
                  // this deactivates the open office DTD
                  return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
                else return null;
    });it still continues to download the dtd.
    Any suggestions?
    Thanks,
    Sam

                        MyDocumentBuilder.setEntityResolver(
                             new EntityResolver() {
                                  public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, java.io.IOException {
                                       if(true){
                                            throw new IOException(publicId +"|"+ systemId);
                                       return null ;
                        );Good eye - It looks like that IOException is never being called - any suggestions?
    Thanks,
    Sam

  • URGENT:  javax.xml.parsers.DocumentBuilder.parse() method issue

    Hi folks,
    I have an urgent parsing problem. I developed an app with JDK1.4 and now it needs to run on JDK1.3.1. The problem is this:
    If I use the DocumentBuilder.parse() method shipped with JDK1.4 it will parse a document containing namespaces WITHOUT a namespace declaration in the root element. However, since XML support doesn't ship with JDK1.3.1 I need to use JAXP. If I try this with the DocumentBuilder.parse() version shipped with JAXP (latest version) the parse method throws a NullPointerException. If I put the namespace declaration in the document it will parse fine. I tried setting the DocumentBuilderFactory.setNamespaceAware() explicitly to false (should be the default) but no luck. Any ideas other than adding the declaration (long story why I don't want it there...)
    thanks

    example, with declaration of namespace:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root xmlns:inn="http://blablabla/inn/version/1.0/">
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    example, without declaration:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root>
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    this may help...

  • Can a method return more than one value?

    I was studying for my biology exam and I got bored and I started thinking and then I wandered if a method can return more than one value...?
    For example, if I want a method to return a row a column, I make a method that returns an int. But what if I want to return two ints? Or what If I want to return an integer and a string? Is it possible or do I have make two methods, each returning one thing?
    What I always did until now is is I want for example to return a few integers, I would store them in a String and then when I return the string, I parse the numbers out using stringtokenizer... but it doesn't look like the best way... and it's pretty annoying...

    I'm weak on terminology, hence I don't even know what
    AFAIK means...As Far As I Know
    This doesn't really make sense for me. It's more
    efficient to make a whole class just for two
    integers, than having two methods? Efficiency is not the point. The flow is.
    If you have two methods, the caller must be aware of both of them. The other way it's up to the callee.
    Just because the
    two integers are related to each other? Doesn't
    making a class require more memory usage than just
    making two one-line methods?The memory usage is not wholly irrelevant, but there are ways to handle that (caching, inlining, etc.).
    It's a bit hard to counter your point for me, but if you had done a lot of GUI painting stuff, you'd see all those Points, Dimensions, Rectangles, you name it, are quite invaluable.

  • Null values returned when using request.getParameters(

    I have a html form which allows the user to choose options and select a file to upload. When I use method=Post I get null values returned. When I use method=Get I get my parameter values fine.. but I get an error.
    "Posted content type isn't multipart/form-data"
    I would like to know why I am getting null values returned when using Post. I am using the following to get the values from the name=value passed to the servlet.
    String strIndustry = request.getParameter("frmIndustry");
              String strCompany = request.getParameter("frmCompany");
              String strCollabType = request.getParameter("frmCollaboration");
    I have another form where the user can search information in a database that works just fine w/ either Get or Post
    Or perhaps I am using oreilly MultipartRequest incorrectly??? but I copied it directly from another discussion.. ???
    any thoughts
    Thanks

    taybon:
    you could do it like this. in this case, you submit your form with the parameters (industry, company, collaboration), and upload your file at the same time. and in the target servlet, you can build your MultipartRequest object like this:
    MultipartRequest multi = new MultipartRequest(request, temp_location, 50 * 1024);where variable temp_location stands for a temporatory diretory for file uploading.
    and then you get your parameters, so you can build the directory with them. and after that, you can move your file to that directory using File.renameTo();
    but as i've suggested in my previous posting, i just recommend you upload your file in a separate form. and then you can perform an oridianry doPost form submit with those parameters. or you may have problems with the file uploading. (this is just my personal experiences with Multipart).
    there is one other thing i'd like to mention, file.renameTo() won't work if you need to move files to a network drive in windows. it won't work if you move files across file systems in unix.
    Song xiaofei
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers/support

  • [OBIEE-11g] Error getting Nqid always null value

    Hi to all, I've a problem to load Nqid in a dashboard on 11g OBIEE.
    The javascript function return always a null value and the document.cookie instruction return an empty string ...
    somebody could help me ?!
    p.s.: in the firefox properties there is a cookie that contain the id but i can't read it
    function getNqid() {
    var nameEQ = 'nQuireID=';
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
    var c = ca;
    while (c.charAt(0)==' ')
    c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0)
    return c.substring(nameEQ.length,c.length);
    return null;

    Hi,
    You might want to check the NQQuery.log to see the code that it is running before making a connection. Just to confirm that the connection pool step is working fine, could you try with a simple select statement and see that it does not error out. If it does not, you may want to revisit the procedure code again. I understand from the error that it is expecting something after the END statement (kind of weird though!!). I assume in this case, it could not parse that this is a stored procedure call itself may be. One thread I found is http://stackoverflow.com/questions/4270818/ora-06550-and-pls-00103 which you may want to look for the line break characters.
    Hope this helps.
    Thank you,
    Dhar

  • Parse method of JAXP DocumentBuilder using InputStream

    I am having some problem. I am working on a generic XML messaging client server pair. The crux of it is that I am using the Transformer object to send data from the client to the server, using a Socket InputStream. The I do exactly the same from the server side to the client side.
    Example (client side):
    OutputStream out = socket.getOutputStream();
    Transformer transformer =
    TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(request),
    new StreamResult(out));
    Example (server side, in the thread for the connection):
    InputStream in = socket.getInputStream();
    DocumentBuilder builder =
    DocumentBuilderFactory.newInstance
    ().newDocumentBuilder();
    Document request = builder.parse(in);
    The problem I am experiencing is that the parse method on the server side is never completing. The parse method does not return at all. I can understand that this is due to the InputStream still being open, and need to know how can I let the parse method know that I am done writing to the OutputStream at the client side. Should I be sending an EOF character of sorts? If I should, what byte value represents this, and what do I need to do?
    Thank you
    Heinrich Pool

    Sorry hadn't noticed the Code Tags before. So the code formatted
    package de.gaskin.xml;
    import de.gaskin.buf.Buffer;
    import de.gaskin.io.LineArray;
    import de.gaskin.util.Debug;
    import java.net.Socket;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.io.ByteArrayOutputStream;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.util.Vector;
    import org.w3c.dom.Document;
    A Simple to use generic XML Document transfer based on sockets.
    <H2>Theory of Operation.</h2>
    <p>A client sends an array of lines (an XML document) prepended by a line
    that ONLY contains an integer (the number of lines in the document that
    follows).
    <p>The server reads the first line (so that it knows how many lines belong to
    the next document) it then reads the specified number of lines into memory and
    when all lines have been read in passes them (as an InputStream) to an
    XMLParser to produce an XML DOM that is made available through the<br>
    <code>getDocument()</code> method.
    <h2>API</h2>
    The API is very simple to use as the following templates demonstrate.
    <h3>Client</h3>
    <pre>
        public class MyXmlSocketClient extends XmlSocket {
           MyXmlSocketClient(String serverAddress, String fileName) {
              super(serverAddress, 4711);
              run(fileName);
    </pre>
    <h3>Server Worker</h3>
        <pre>
        public class MyXmlSocketServer extends XmlSocket {
           MyXmlSocketServer(Socket s) {
              super(s);
           public void run() {
              Document doc = getDocument();
              // Process document
        </pre>
    <h3>Server Listener</h3>
        <pre>
        public class MyXmlServer {
           ServerSocket ss;
           boolean      stop;
           MyXmlSocketServer() {
              stop = false;
              try {
                 ss = new ServerSocket(4711);
                 while (! stop) {
                    Socket s = ss.accept();
                    new Thread(new MyXmlServerSocket(s));
              catch (Exception x) {
                 x.printStackTrace();
        </pre>
    <P>Last updated 10th Jan 2001.
    @author  David. M. Gaskin.
    @version Version 1.0 Oct 2000
    @since    Version 1.0
    public class XmlSocket implements Runnable {
       final static boolean debug = false;
       protected BufferedReader  data;
      /* protected */ public PrintWriter     pw;
                 Socket          socket;
       public XmlSocket(String domain, int port) {
          try {
             socket = new Socket(domain, port);
             common(socket);
          catch (Exception x) {
    //       x.printStackTrace();
             throw new Error(x.toString());
       public XmlSocket(Socket s) {
          socket = s;
          common(s);
       void common(Socket s) {
          try {
             data = new BufferedReader(new InputStreamReader(s.getInputStream()));
             pw   = new PrintWriter(s.getOutputStream(), true);
          catch (Exception x) {
    //       x.printStackTrace();
             throw new Error(x.toString());
       public Document getDocument() {
          Document rc = null;
          try {
             String line = data.readLine();
             int    linesInDoc = Integer.parseInt(line.trim());
             if (linesInDoc != -1) {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                for (int i = 0;i < linesInDoc;i++) {
                   line = data.readLine();
                   System.out.println(line);
                   byte[] byteLine = line.getBytes();
                   os.write(byteLine, 0, byteLine.length);
    //          System.out.println("END");
                rc = XmlFactory.readIn(new ByteArrayInputStream(os.toByteArray()));
          catch (Exception x) {
             x.printStackTrace();
          return rc;
       public void run(Vector lines) {
          int loopCnt = lines.size();
          if (debug) {
             println("" + loopCnt);
             for (int i = 0;i < loopCnt;i++) {
                println((String)lines.elementAt(i));
    //       pw.flush();
             println("-1");
          else {
             pw.println("" + loopCnt);
             for (int i = 0;i < loopCnt;i++) {
                pw.println((String)lines.elementAt(i));
    //       pw.flush();
             pw.println("-1");
          pw.flush();
       void println(String s) {
          System.out.println(s);
          pw.println(s);
       public void run() {
          Debug.d(this, "run", "S H O U L D   N E V E R   B E   I N V O K E D");
       public void run(String filename) {
          Buffer[] input = LineArray.readIn(filename);
          send(input);
       public void run(File file) {
          Buffer[] input = LineArray.readIn(file.getAbsolutePath());
          send(input);
       void send(Buffer[] input) {
          int loopCnt = input.length;
          pw.println("" + loopCnt);
          for (int i = 0;i < loopCnt;i++) {
             pw.println(input.toString());
    pw.flush();
    pw.println("-1");
    pw.flush();
    public int getDocIdx(String[] roots, Document doc) {
    int rc = -1;
    String rootName = doc.getDocumentElement().getTagName();
    int loopCnt = roots.length;
    for (int i = 0;i < loopCnt;i++) {
    if (rootName.equals(roots[i])) {
    rc = i;
    break;
    if (rc < 0)
    System.out.println(rootName + " N O T F O U N D");
    return rc;
    public Socket getSocket() {
    return socket;
    For testing only
    public static void main(String[] args) {
    XmlSocket xmlS = new XmlSocket("localhost", 36);
    xmlS.getDocument();

  • Calling a method of a returned reference

    Hello,
    is it possible to instantly do a method call on a returned reference in ABAP Objects? in this case i need it for singleton behaviour of "z_example", but the compiler wont allow me to call like this:
    result = z_example=>get_instance( )->do_stuff( input_param another_param ).
    i tried several other syntaxes (is this the right plural ), but it wasn't successful. in java its a standard thing:
    result = Example.getInstance().doStuff(inputParam, anotherParam);
    Thanks in advance,
    Stefan

    Hello Stefan
    In 6.20 and 6.40 I do not think this is possible. In your example you have to invoke the method on result.
    Perhaps with release >= 700 it may be possible.
    Regards
        Uwe

  • Hi,i am trying to edit a BP and i get this error;An attempt was made to execute a dynamic method callon an initial(NULL-) object reference. The reference must refer to an object. what could be missing?

    BP_....AccountActivitiesOV.htm....application BPBT.
    what could be wrong? An attempt was made to execute a dynamic method callon an initial(NULL-) object reference. The reference must refer to an object???

    Hi Dunamis,
    Please check if below links can help you;
    Error on execution of Web Interface
    Help! I meet this Business Server Page (BSP) error CX_SY_REF_IS_INITIAL
    Strange Error in Transformation of 2LiS_03_BF with 0IC_C03
    Regards,
    Kamfrk.

  • When passing Node to parse() method get NULL pointer exception.

    All,
    I trying to pass a Node to parse method to get the NodeType object back and getting
    null pointer exception.
    Example
    xml
    <root>
    <Test>
    <someData>ABC</someData>
    </Test>
    </root>
    if pass the Test node to get Test object back I am getting null pointer exception.
    Thanks for all ur help
    Shoeb

    file 2
    ~~~~
    import javax.swing.*;
    public class ExtendedPage extends BasePage
    private JTextField objJTextField = null;
    private JButton objJButtonBrowse = null;
    Change the line in bold to
    private JTextField objJTextField;
    And everything works.

  • Looks like some Exceptions' getMessage() methods return null

    Looks like some Exceptions' getMessage() methods return null instead of the message.
    -Andrew

    snidely_whiplash wrote:
    Looks like some Exceptions' getMessage() methods return null instead of the message.
    -AndrewDoes it return a null object, or does it return "null" as a String? The latter may be a case of using the message from a wrapped exception, which in case of a NullPointerException is frequently null (if the NPE was not constructed intentionally with a message).
    BR,
    Robert

  • Syntax Error with JSON.Parse method to parse SharePoint List Items

    Hi All,
    I want to get SharePoint List data and bind that retrived data to the JQuery Grid Control.
    For this I used SPServices to get the SharePoint List data in SOAP Envelope. Now I need to parse the soap envelope and store the retrieved items in array to pass it to the Grid Control.
    While using the JSON.Parse(resporseText) method, Iam consistenly getting an Syntax Error!
    Could anyone help me with this ?
    Please find the SOAP Envelope I received from SP List as below:
    "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
    <rs:data ItemCount="2">
    <z:row ows_OBNumber='112211.000000000' ows_Project_x0020_Name='Project 1' ows_MetaInfo='11;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 1' ows_ID='11' ows_UniqueId='11;#{FBBCBCF9-666D-42F9-92D7-67188C51BC9B}' ows_owshiddenversion='1' ows_FSObjType='11;#0' ows_Created='2015-01-12 10:25:06' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:25:06' ows_FileRef='11;#sites/Lists/Projects/11_.000' />
    <z:row ows_OBNumber='1122343.00000000' ows_Project_x0020_Name='Project 2 ' ows_MetaInfo='12;#' ows__ModerationStatus='0' ows__Level='1' ows_Title='Project 2' ows_ID='12' ows_UniqueId='12;#{0D772B76-68E4-4769-B6FF-6A269F9C7ABD}' ows_owshiddenversion='1' ows_FSObjType='12;#0' ows_Created='2015-01-12 10:33:48' ows_PermMask='0x7fffffffffffffff' ows_Modified='2015-01-12 10:33:48' ows_FileRef='12;#sites/Lists/Projects/12_.000' />
    </rs:data>
    </listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>"
    Any help on this will be greatly appreciated.
    Thanks In Advance.!

    Hi,
    According to your description, there is an issue when parsing result from the data retrieved using SPServices.
    By default, SPServices returns data as XML format, however, the JSON.parse() method “Throws a SyntaxError exception if the string to parse is not valid JSON”:
    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
    To extract the data needed from the response, you can either take the demo below for as a reference:
    http://spservices.codeplex.com/wikipage?title=GetListItems
    Or use the jQuery.parseXML() function:
    http://api.jquery.com/jquery.parsexml/
    Best regards
    Patrick Liang
    TechNet Community Support

  • Java.lang.NullPointerException javax.xml.parsers.DocumentBuilder.parse

    Hi all,
    i have a problem by solving an error in my code. The Code is mainly from Ian Darwin.
    The code i am running works with j2sdk1.4.2_04. But now i have to bring it to work with jdk1.6.0_13.
    The code parses xml documents. With small xml documents the code works. With large xml documents i get the following error while running the produced class file.
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944)
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644)
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
    at XParse.parse(XParse.java:38)
    at XParse$JFileChooserrv.<init>(XParse.java:119)
    at XParse.main(XParse.java:213)
    I know what a java.lang.NullPointerException mens. But i don't know where i have to look for. Specially i don't know what or where "com.sun.org.apache...." is.
    Is there a package that a have to add to the environment? Can some one tell my where i can find this package?
    I wrote the code for some years ago, 2006 or so. With the knew jdk1.6.0_13 some thinks chance in the environment. Couldn't find what exactly.
    The code has only 215 lines, but some how i can't add it to this Message, because Maximum allowed is only 7500.
    Is there an other Forum, which may is better for my question?

    Here is the code:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Container;
    import javax.swing.JTextArea;
    * This code is mainly from @author Ian Darwin, [email protected]
    public class XParse {
         /** Convert the file */
         public static void parse(File file, boolean validate) {
              try {
                   System.err.println("");
                   String fileName = file.getAbsolutePath();
                   System.err.println("Parsing " + fileName + "...");
                   // Make the document a URL so relative DTD works.
                   //String uri = new File(fileName).getAbsolutePath();
                   //System.err.println(uri);
                   DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
                   if (validate)
                   f.setValidating(true);
                   DocumentBuilder p = f.newDocumentBuilder();
                   p.setErrorHandler(new MyErrorHandler(System.err));
                   //XmlDocument doc = XmlDocument.createXMLDocument(file);
                   boolean vaild =  p.isValidating();
                   if (vaild) {
                        System.out.println("yes parsing");
                        Document doc = p.parse(file); // <<<< ERROR
                   System.out.println("Parsed OK");
              } catch (SAXParseException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("At line " + ex.getLineNumber());
                   System.err.println("+================================+");
              } /**catch (RuntimeException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   //System.err.println("At line " + ex.getLineNumber());
                   //System.err.println("At line " + ex.getMessage());
                   System.err.println("+================================+");
              }**/ catch (SAXException ex) {
                   System.err.println("+================================+");
                   System.err.println("|          *SAX Error*           |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("+================================+");
              /*}} catch (SAXNotRecognizedException  ex) {
                   System.err.println(" no SAX");*/
              } catch (ParserConfigurationException ex) {
                   System.err.println(" ???");
               } catch (IOException ex) {
                   System.err.println("+================================+");
                   System.err.println("|           *XML Error*          |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
    private static class JFileChooserrv {
         JFileChooserrv(JFrame f, boolean vverabreiten) {
              String openfile;
              String verror;
              boolean validate = true;
              final JFrame frame = f;
              String vFilename = "Z:\\Boorberg\\parsen_vista\\daten";
              //String vFilename = "C:\\";
              File vFile = new File(vFilename);
              final JFileChooser chooser = new JFileChooser(vFile);
              JFileFilter filter = new JFileFilter();
              filter.addType("xml");
              filter.addType("sgml");
              filter.addType("html");
              filter.addType("java");
              filter.setDescription("strukturfiles");
              chooser.addChoosableFileFilter(filter);
              boolean vjeas = true;
              chooser.setMultiSelectionEnabled(vjeas);
              int returnVal = chooser.showOpenDialog(frame);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   //Array  filearry[] = chooser.getSelectedFiles();
                   //if (vFile = chooser.getSelectedFiles()) {
                   //File  file[] = chooser.getSelectedFiles();
                   File  vfile[] = chooser.getSelectedFiles();
                   //String openfile = new String();
                   int vlenght = vfile.length;
                   if (vlenght>1) {
                        int x=0;
                        while (x< vlenght) {
                                  parse(vfile[x], validate);
                                  x = x +1;
                   if (vlenght<=1) {
                        File v2file = chooser.getSelectedFile();
                             parse(v2file, validate);
              } else {
                   System.out.println("You did not choose a filesystem           object.");
         System.exit(0);
    private static class JFileFilter extends javax.swing.filechooser.FileFilter {
         protected String description, vnew;
         protected ArrayList<String> exts = new ArrayList<String>();
         protected boolean vtrue;
         public void addType(String s) {
              exts.add(s);
         /** Return true if the given file is accepted by this filter. */
         public boolean accept(File f) {
              // Little trick: if you don't do this, only directory names
              // ending in one of the extentions appear in the window.
              if (f.isDirectory()) {
                   return true;
              } else if (f.isFile()) {
                   Iterator it = exts.iterator();
                   while (it.hasNext()) {
                        if (f.getName().endsWith((String)it.next()))
                             return true;
              // A file that didn't match, or a weirdo (e.g. UNIX device file?).
              return false;
         /** Set the printable description of this filter. */
         public void setDescription(String s) {
              description = s;
         /** Return the printable description of this filter. */
         public String getDescription() {
              return description;
    private static class MyErrorHandler implements ErrorHandler {
            // Error handler output goes here
            private PrintStream out;
            MyErrorHandler(PrintStream out) {
                this.out = out;
             * Returns a string describing parse exception details
            private String getParseExceptionInfo(SAXParseException spe) {
                String systemId = spe.getSystemId();
                if (systemId == null) {
                    systemId = "null";
                String info = "URI=" + systemId +
                    " Line=" + spe.getLineNumber() +
                    ": " + spe.getMessage();
                return info;
            // The following methods are standard SAX ErrorHandler methods.
            // See SAX documentation for more info.
            public void warning(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                //out.println("Warning: " + getParseExceptionInfo(spe));
            public void error(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
            public void fatalError(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Fatal Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
         public static void main(String[] av) {
              JFrame vframe = new JFrame("chose files to pars");
              boolean vverabreiten = true;
              boolean validate = true;
              JFileChooserrv vdateienwaehlen = new JFileChooserrv(vframe, vverabreiten);
    }The Stack Trace i posted in the last Message. But i couldn't read it, i am not a programmer.

  • Parse method hangs

    I am trying to to parse a file using DocumentBuilder. The parse() method hangs for no reason. There are no errors or exceptions thrown. I even used a StringReader but in vain. Pl see code below:
    The file is read correctly and i could even print the XML string out.
    System.out.println("Parsing XML file from performParsing():" +s);
              Document doc = null;
              DocumentBuilderFactory factory = null;
              DocumentBuilder builder = null;
              try{
                   factory = DocumentBuilderFactory.newInstance();
                   System.out.println("Parsing XML factory:" +factory);
                   builder = factory.newDocumentBuilder();
                   System.out.println("Parsing XML builder:" +builder);
                   URL url = new URL(s);
                   URLConnection urlConnection = url.openConnection();
                   InputStream in = urlConnection.getInputStream();
                   String XMLStr = getStringReaderFromFile(in); //private method that gives a string
                   StringReader stReader = new StringReader(XMLStr);
                   InputSource ins = new InputSource(stReader);
         doc = builder.parse(ins);--->IT HANGS HERE

    Not an expert on this but presumably you have the properties set up correctly.
    From javadoc ...
    DocumentBuilderFactory uses the system property javax.xml.parsers.XmlDocumentParserFactory to find the class to load. So you can change the parser by calling:
    System.setProperty("javax.xml.parsers.XmlDocumentParserFactory",
    "com.foo.myFactory");

  • Possible to overwrite parse method in DOM with SAX Handler?

    Hi,
    Is it possible to overwrite the parse method within DOM?
    What a want to do is:
         private Node parseXml( String text ) throws SAXParseException, SAXException, IOException, ParserConfigurationException
              SAXParserFactory factory = SAXParserFactory.newInstance();
                   factory.setNamespaceAware(true);
                   SAXParser parser = factory.newSAXParser();
                   TestHandler handler = new TestHandler();
                   // Parse the file
                   parser.parse(new InputSource(new StringReader(text)), handler);
              return (Node)handler.getRoot();
         } //end parseXml()The reason I want to use this is that within SAX I can write my own line counter so I keep a count of which node is on which line of text.
    What I was thinking is that I could use SAX to return DOM Nodes with the line number attached, possibly using the node.setUserData() method?!
    I have tried to play around with it and it doen't seem to work, can anyone help?
    Cheers Alex

    I have managaed to re-write my SAX parser to create a JTree, this works perfectly I can move through the tree and each line of text that corresponds to the node is highlighted.
    My problem is however that in my application I have used the DOM structure throughout so some of the functionality is lost.
    Is I understand that JAXP uses both SAX and DOM together, so I was wondering if it is possible to combine my sax parse method within the DOM?
    If anything is unclear please say and I will try and explain better. The main reason for doing this is that I want to keep a reference to which line of text each node of the dom tree represents. I have not been able to implemnet one in DOM however using SAX I have managed.
    Many thanks,
    Alex

Maybe you are looking for