This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New Line Character not recognized

 
Shweta Gulati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to read the XML file using the DOM Parser and one of the lines in that XML file has value with new line characters i.e \n. Now when i try to write the data retrieved i.e. the line with the new line character in the text area then the new line character is appearing as it is. i.e. instead of printing the text appearing after \n in a new line it is printing \n followed by the text in the same line.
For eg.
If the text read from XML file is
"Please write this to a \n new line."
The result expected in the text area would be
Please write this to a
new line.
But the result that I am getting is
Please write this to a \n new line.
The same thing if I hard code in a String variable and setText of the textarea with this hard coded value it is giving expected result i.e.
Please write this to a
new line.
Thanks a lot.
Shweta
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\n is an escape sequence in java source code and is translated at compile time to the corresponding character as defined by the synctactic rules of java.
XML has its own syntactic rules, which are totally independent of the ones of java. After all, you want to have XML files be handled identically regardless of the programming language used to parse it.
So you have to use the XML rules to insert the newline character.
 
saager mhatre
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be using '\\n' to actually put the '\' in the output. Use only '\n' to get the desired output
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic