Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

New Line Character not recognized

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic