This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML question" Watch "XML question" New topic
Author

XML question

John Ip
Ranch Hand

Joined: Mar 04, 2004
Posts: 45
Hi all,

I am writing a xml file writer to write an xml file and store it in the file system. And I have another xml file reader to read the xml file. I have the following situation.

I add a Text node into the DOM and the value is a string (eg. "First Thing\r\nYou need to do this\r\nSecond\r\nYou need to do that" )with new line characters "\r\n". I replaced all the "\r\n" with "\n". And I assign the string to the value of the text node. I use text.getNodeValue() to confirm the value I put into the text node is "First Thing\nYou need to do this\nSecond\nYou need to do that". It prints out as I expected.

However, when I read the xml file with my xml file reader program, all the "\n" characters gone....... I use text.getNodeValue().. and i get "First Thing You need to do this Second You need to do that". Why is that? Can any one give me a clue?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42359
    
  64
What about the file that is written to disk? Does it have the newlines? What library do you use to read and write the file?


Ping & DNS - my free Android networking tools app
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi John,
The section is for question related to webservices, I am moving your post to our XML and related technologies forum for better visibility.
Regards
Balaji
John Ip
Ranch Hand

Joined: Mar 04, 2004
Posts: 45
I am using the org.w3c.dom comes with the J2SDK.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
If you look at the XML document file with a text editor, are the line breaks there?
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML question