Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 8944
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.
 
Marshal
Posts: 27211
87
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
 
Attractive, successful people love this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic