Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Rid of ">" when writing XML

Status
Not open for further replies.

jl280328

Programmer
Jun 15, 2006
97
US
I have a program that reads in a text file and writes it out as an XML file. The problem is that whenever I come across a greater than or less than sign it is being displayed as this "&gt;" and "&lt;" is there anyway to keep this from happening so when the XML file is opened up it uses the ">" and "<" signs?
 
also I am using the XMLTextwriter to write this file out and the .WriteElementString(TagName, Value) to write it out.
 
&gt; and &lt; are the correct ways to represent the > and < characters in an XML file. See the W3C web site, and search for "character entities". There's also the & character, which is represented as &amp; and the ' character, which is &apos; (often seen when writing names like O'Malley into an element).

If the person/system you're exchanging these files with are having problems reading this, they'll need to use an XML parser that follows the standards.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I am working with these same tools. When building the XML file, we replace the 5 dangerous characters (&,',",<,>) with the HTML equivalents. Then on the recieving end, I wrote a function to re-replace the HTML chars with the regular text chars. (The XML reader in the program I am working on isn't able to do the replacvment on it's own, and I don't have time to look for another reader right now, so I wrote the code.)

Long story short, whoever is receiving the XML file has no choice but to either use an XML parser which is capable of replacing these five HTML characters on it's own, or to write a function to do it.

Also, keep in mind 2 things:

1. Even if you build the XML file without the HTML characters, no XML reader will be able to read it, since those characters make it unreadable. Why? Becuase they are used in the structure of the XML document. Those characters will cancel out the ones that are supposed to be there. How is the XML reader supposed to know which of the > are the structural ones?

2. If the XML file is viewed in a Web browser, the regular text characters will be displayed, and it will look normal.

Good luck!




Greg Norris
Software Developer & all around swell guy


__________________________________________________
Constructed from 100% recycled electrons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top