wood burning stoves 2.0*
The moose likes Java in General and the fly likes special character in xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "special character in xml" Watch "special character in xml" New topic
Author

special character in xml

rose deng
Ranch Hand

Joined: Dec 29, 2000
Posts: 78
Hi,
As far as i know, & and < are special characters for xml. so we need to escape those two characters to make the string be well-formed xml string.
& is easy to handle, just encode it to & ;.afer validation or transformation, decode it back.
My question is how to encode < sign in element value, seems can not just encode it to < ;, since it's hard to differieciated less than sign from open tag
If you have solution, share with me please.
Huge thanks.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
& lt ;
[ February 13, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It looks like Rose was trying to write "&lt;" in the first place, but wrote "&lt ;" (trying to fool UBB) and UBB (or the browser?) converted this to "< ;". Very .
Anyway, to write
<
in UBB type
&lt;
which you in turn get by writing
&amp;lt;
which you in turn get by writing
&amp;amp;lt;
which you in turn get by writing
&amp;amp;amp;lt;
etc. :roll: Usually you just need to go just one or two steps into this progression, but in order to talk about step 1 you need to use step 2, etc.
To anwer what I think was the intended question - when you write a "<", you usually need to know at the time whether it's the beginning of a tag (in which case write it as "<") or part of the text content of a tag (in which case replace it with "&lt;"). I guess it really depends where you're getting this data from, but in most contexts I can imagine you should already know if it's content or markup. The only exception I can think of is if you're reading an XML file which was not properly encoded to beging with, and you're trying to fix it. But perhaps you (Rose) should tell us more about where the data comes from, before we get into all the possibilities here.
[ February 13, 2003: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: special character in xml
 
Similar Threads
Using characters like quote, ampersand in xml
Unicode parsing exception
HTML file within an XML file
ask for solution to encode less than sign in string to make the string xml-compliant
I need the URL unicode representation of <> angle brackets?