Results 1 to 4 of 4
  1. #1
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    79
    Rep Power
    0

    Default JAVA DOM XML error

    Hi,

    I try to create a new xml file with DOM parser and i get this error in line 73, can ant one help me ?


    Java Code:
    package RunMABS;
    
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Attr;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    
    
    public class dokimes {
        
    public static void main(String[] args)  {
    
        try {
     
    		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
     
    		// root elements
    		Document doc = docBuilder.newDocument();
    		Element rootElement = doc.createElement("company");
    		doc.appendChild(rootElement);
     
    		// staff elements
    		Element staff = doc.createElement("Staff");
    		rootElement.appendChild(staff);
     
    		// set attribute to staff element
    		Attr attr = doc.createAttribute("id");
    		attr.setValue("1");
    		staff.setAttributeNode(attr);
     
    		// shorten way
    		// staff.setAttribute("id", "1");
     
    		// firstname elements
    		Element firstname = doc.createElement("firstname");
    		firstname.appendChild(doc.createTextNode("yong"));
    		staff.appendChild(firstname);
     
    		// lastname elements
    		Element lastname = doc.createElement("lastname");
    		lastname.appendChild(doc.createTextNode("mook kim"));
    		staff.appendChild(lastname);
     
    		// nickname elements
    		Element nickname = doc.createElement("nickname");
    		nickname.appendChild(doc.createTextNode("mkyong"));
    		staff.appendChild(nickname);
     
    		// salary elements
    		Element salary = doc.createElement("salary");
    		salary.appendChild(doc.createTextNode("100000"));
    		staff.appendChild(salary);
     
    		// write the content into xml file
    		TransformerFactory transformerFactory = TransformerFactory.newInstance();
    		Transformer transformer = transformerFactory.newTransformer();
    		DOMSource source = new DOMSource(doc);
                    StreamResult result = new StreamResult(new File("C:\\file.xml"));
    
     
    		// Output to console for testing
    		// StreamResult result = new StreamResult(System.out);
     
    		transformer.transform(source, result); <--- the problem is here
     
    		System.out.println("File saved!");
     
    	  } catch (ParserConfigurationException pce) {
    		pce.printStackTrace();
    	  } catch (TransformerException tfe) {
    		tfe.printStackTrace();
    	  }
    
    }
        
    }


    Java Code:
    Exception in thread "main" java.lang.AbstractMethodError: gnu.xml.dom.DomDocument.getXmlStandalone()Z
    	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:377)
    	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:131)
    	at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
    	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:702)
    	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:746)
    	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:359)
    	at RunMABS.dokimes.main(dokimes.java:73)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds))

    Thank you in advanced

    ki_ha1984

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: JAVA DOM XML error

    You've got some jar file mismatch going on.
    Are you by any chance using JFreeChart?
    Seems they use some Gnu implementation that might not be compatible (gnujaxp ?).
    Find that jar and remove it from your execution classpath.

    ETA:
    And I got that from a 5 second Google on:
    AbstractMethodError: gnu.xml.dom.DomDocument.getXmlStandalone
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    79
    Rep Power
    0

    Default Re: JAVA DOM XML error

    Thank you very much my friend,
    Yes was introduce the JFreeChart, now i remove it and don't have the problem.

    Also one more question
    When i open the XML file with any editor i get those results, all in one line

    Java Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?><company><Staff id="1"><firstname>yong</firstname><lastname>mook kim</lastname><nickname>mkyong</nickname><salary>100000</salary></Staff></company>
    Is there any way to make it like this, more easy readable

    Java Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    	<company>
    		<Staff id="1">
    			<firstname>yong</firstname>
    			<lastname>mook kim</lastname>
    			<nickname>mkyong</nickname>
    			<salary>100000</salary>
    		</Staff>
    	</company>
    Thank you

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: JAVA DOM XML error

    Transformer has a setOutputProperty method.
    You want to set the INDENT property to "yes" before transforming. This should properly indent your output.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 6
    Last Post: 02-11-2013, 06:22 AM
  2. Replies: 3
    Last Post: 05-08-2012, 06:26 PM
  3. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 05:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •