3 Replies Latest reply: Nov 17, 2009 7:59 AM by 843790 RSS

    XML parser

    843790
      Here's a test code to convert document to xml from some website (http://www.roseindia.net/xml/dom/CreatXMLFile.shtml)
      and it works perfectely fine if I run it independently in eclipse.

      I have given problem details after the code.
      import java.io.*;
      import javax.xml.parsers.*;
      import javax.xml.transform.*;
      import javax.xml.transform.dom.*;
      import javax.xml.transform.stream.*;
      import org.w3c.dom.*;
       
      public class CreatXMLFile {
           public static void main(String[] args) throws Exception {
                BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
                System.out.print("Enter number to add elements in your XML file: ");
                String str = bf.readLine();
                int no = Integer.parseInt(str);
                System.out.print("Enter root: ");
                String root = bf.readLine();
                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
              DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
              Document document = documentBuilder.newDocument();
                Element rootElement = document.createElement(root);
              document.appendChild(rootElement);
                for (int i = 1; i <= no; i++){
                     System.out.print("Enter the element: ");
                     String element = bf.readLine();
                     System.out.print("Enter the data: ");
                     String data = bf.readLine();
                     Element em = document.createElement(element);
                     em.appendChild(document.createTextNode(data));
                     rootElement.appendChild(em);
                }
                TransformerFactory transformerFactory = TransformerFactory.newInstance();
              Transformer transformer = transformerFactory.newTransformer();
              DOMSource source = new DOMSource(document);
              StreamResult result =  new StreamResult(System.out);
              transformer.transform(source, result);
           }
      }
      Now when I integrate this fully functional code with my project, and try to run it.
      Just to reproduce the error, I have switched off all other functionality except calling the above code in one of my methods.

      The code gives an error at line transformer.transform(source, result);*

      The given error is: -
      Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: gnu.xml.dom.DomDocument.getXmlStandalone()Z
           at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(Unknown Source)
           at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
           at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
           at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
           at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
           at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
           at simulav.dbInterface.XmlInterface.exportToXml(XmlInterface.java:990)
           at simulav.data.Data.export(Data.java:180)
           at simulav.MainController.exportElement(MainController.java:328)
           at simulav.gui.ActionFactory$ExportAction.actionPerformed(ActionFactory.java:638)
           at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
           at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
           at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
           at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
           at javax.swing.AbstractButton.doClick(Unknown Source)
           at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
           at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
           at java.awt.Component.processMouseEvent(Unknown Source)
           at javax.swing.JComponent.processMouseEvent(Unknown Source)
           at java.awt.Component.processEvent(Unknown Source)
           at java.awt.Container.processEvent(Unknown Source)
           at java.awt.Component.dispatchEventImpl(Unknown Source)
           at java.awt.Container.dispatchEventImpl(Unknown Source)
           at java.awt.Component.dispatchEvent(Unknown Source)
           at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
           at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
           at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
           at java.awt.Container.dispatchEventImpl(Unknown Source)
           at java.awt.Window.dispatchEventImpl(Unknown Source)
           at java.awt.Component.dispatchEvent(Unknown Source)
           at java.awt.EventQueue.dispatchEvent(Unknown Source)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
           at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
           at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
           at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
           at java.awt.EventDispatchThread.run(Unknown Source)
      One possible reason I found online is
      http://www.velocityreviews.com/forums/t370811-java-lang-abstractmethoderror-at-the-org-apache-xerces-dom-domimplementationimpl-createlsoutput.html

      This error indicates that you are running against a different
      class than the one you compiled again.

      Obviously your usage of XML parser libraries at compile time
      and runtime are not consistent.

      But I don't know how to check the XML parser libraries.
      If any further information is required, I will respond as quickly as possible.
        • 1. Re: XML parser
          843790
          Basically that error message means that the code at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo tried to call the void method gnu.xml.dom.DomDocument.getXmlStandalone(), but it couldn't be found.

          In this context it probably means that you are using a broken (i.e. too old) XML parser. Personally I've never seen an XML parser in the package gnu.xml.dom. I'm pretty sure that you won't have that as the default if you're using a Sun JRE.

          Which JRE/JDK are you using to run that code?
          • 2. Re: XML parser
            843790
            Yes, the problem was with one of the JAR files (gnujaxp.jar).

            It contained old versions of some of the following import directories.
            import java.io.*;
            import javax.xml.parsers.*;
            import javax.xml.transform.*;
            import javax.xml.transform.dom.*;
            import javax.xml.transform.stream.*;
            import org.w3c.dom.*;
            To be precise, I had to remove the gnujaxp.jar directory from classpath, and rebuild the code.

            Thanks.
            • 3. Re: XML parser
              843790
              vkaushal21 wrote:
              Here's a test code to convert document to xml from some website (http://www.roseindia.net/xml/dom/CreatXMLFile.shtml)
              and it works perfectely fine if I run it independently in eclipse.
              Contradictory information. Something from roseindia can't possibly work, let alone work perfectly.