• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

not able to create XML through DOM...

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

Thanks.
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is doc.appendChild(rootElement)
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradip Bhat:
Where is doc.appendChild(rootElement)



It's 5th line of main method.
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's Right.
Use javax.xml.transform(or transformer whatever!!) package.

Shriniwas
 
Are you here to take over the surface world? Because this tiny ad will stop you!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic