473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

encoding problem

i have xml with the line
<VAL ID="artist" VAL="abc & cde"/>

i need the & character to be there but the xmlDocument Load method throw exception for invalid character.

i don't want to encode the string, can this be done?

using some kind of cofiguration on the XMLDoc object?

TIA, z.

Nov 12 '05 #1
4 2114
z. f. wrote:
i have xml with the line

<VAL ID="artist" VAL="abc & cde"/>

i need the & character to be there but the xmlDocument Load method throw
exception for invalid character.

i don't want to encode the string, can this be done?


Nope. < and & characters must be escaped in XML. Any API that builds XML
is doing that already, so you better generate XML using some XML API
such as XmlTextWriter class.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg,

Is it possible to make the XmlTextWriter escape other characters (especially
@, >, ' and ")?

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> skrev i en
meddelelse news:eh**************@TK2MSFTNGP10.phx.gbl...
z. f. wrote:
i have xml with the line

<VAL ID="artist" VAL="abc & cde"/>

i need the & character to be there but the xmlDocument Load method throw
exception for invalid character.

i don't want to encode the string, can this be done?


Nope. < and & characters must be escaped in XML. Any API that builds XML
is doing that already, so you better generate XML using some XML API such
as XmlTextWriter class.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Benny Tordrup wrote:
Is it possible to make the XmlTextWriter escape other characters (especially
@, >, ' and ")?


I don't think so. Why?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
Because I'm working with a project that creates a XML file.

The encoding is required to be "ISO-8859-1". Next, it is requiret that the
characters @ < > & ' " does not occur in the data in the file and must be
escaped by the values (respectively) &at; &lt; &gt; &amp; &apos; &quot;

I'm writing the XMLDocument using a XmlTextWriter with the encoding set to
ISO-8859-1.
The encoding does not handle theese character escapings (it does handle
escaping of &, which destroys my tries to do a search and replace of the
characters).

I've managed to solve it by using the WriteRaw method of the XmlTextWriter,
but this forces me to use the XmlTextWriter object constantly instead of
adding nodes to the XmlDocument instance and then writing this instance to a
file using the XmlTextWriter object.

Benny
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> skrev i en
meddelelse news:u3**************@tk2msftngp13.phx.gbl...
Benny Tordrup wrote:
Is it possible to make the XmlTextWriter escape other characters
(especially @, >, ' and ")?


I don't think so. Why?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ann | last post by:
Hi, Is there any way to Change encoding of Java Vm to ISO-8859-1? i am using Java vm along with an application called opencms. I get the following error message.. Error: the encoding of your...
8
by: janeaustine50 | last post by:
Python's InteractiveInterpreter uses the built-in compile function. According to the ref. manual, it doesn't seem to concern about the encoding of the source string. When I hand in an unicode...
7
by: Mark | last post by:
Hi... I've been doing a lot of work both creating and consuming web services, and I notice there seems to be a discontinuity between a number of the different cogs in the wheel centering around...
8
by: davisjoseph | last post by:
Hi All, I'm newbie to this XML world. My problem is to identify the encoding type of XML at runtime. What currently I'm doing is checking whether BOM is available in the XML; based on the BOM...
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
4
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
3
by: Martin Z | last post by:
Hi, I have an application that involves sending a lot of XML data to various places. The problem is that once in a while, I just want the XML document as a string (for example, sending to a...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.