Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

special character in xml

 
rose deng
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& lt ;
[ February 13, 2003: Message edited by: Thomas Paul ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic