• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to create XML through DOM...

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is doc.appendChild(rootElement)
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradip Bhat:
Where is doc.appendChild(rootElement)


It's 5th line of main method.
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's Right.
Use javax.xml.transform(or transformer whatever!!) package.

Shriniwas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic