aspose file tools*
The moose likes XML and Related Technologies and the fly likes not able to create XML through DOM... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "not able to create XML through DOM..." Watch "not able to create XML through DOM..." New topic
Author

not able to create XML through DOM...

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


Why, I am not getting any XML file on console???

Thanks.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Where is doc.appendChild(rootElement)


Groovy
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Pradip Bhat:
Where is doc.appendChild(rootElement)


It's 5th line of main method.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

That's because the toString() method of Document returns "null". I expect you were assuming that it would return a text representation of the Document, but if you look at the API documentation you will see there is no such promise there.

The usual way to produce an XML document from a DOM is to create a Transformer object whose input comes from the DOM and whose output points where you want the document to go, and to call its transform() method.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Paul Clapham:
That's because the toString() method of Document returns "null". I expect you were assuming that it would return a text representation of the Document, but if you look at the API documentation you will see there is no such promise there.

The usual way to produce an XML document from a DOM is to create a Transformer object whose input comes from the DOM and whose output points where you want the document to go, and to call its transform() method.


Thanks Paul.

But that's not correct, toString() method prints text representation of document.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
But that's not correct, toString() method prints text representation of document.

Look at the JavaDocs for org.w3c.Node - specifically the table showing what the nodeName and nodeValue values are - note that a Document Node returns null for nodeValue.
Now, is some implementations of the DOM, Document.toString returns a full text string BUT in the Java 1.5 implementation, toString returns the result of a call to nodeValue() which is - as seen above - null.
Document is an interface so it does NOT dictate what toString() should return. This has caused a lot of confusion and hunting for bugs that do not exist.
Bill
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
That's Right.
Use javax.xml.transform(or transformer whatever!!) package.

Shriniwas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not able to create XML through DOM...