Xml and DataSets

G

Guest

Is there a way to explicitly escape special characters (particularly &
(&) and ' (')) when writing a data set with the WriteXml
method?

I know this is supposed to happen automatically (according to MS), but
in my case, it doesn't. I'm pulling data from MS-SQL with c#, filling
data tables with SqlDataAdapter and a query, adding tables to a
DataSet, then WriteXml to a file.
 
M

Martin Honnen

Diogo said:
Is there a way to explicitly escape special characters (particularly &
(&) and ' (')) when writing a data set with the WriteXml
method?

I know this is supposed to happen automatically (according to MS), but
in my case, it doesn't.

Well & always needs to be escaped as & unless used to start a
character or entity reference. I am pretty sure WriteXml escapes
ampersands otherwise its output is not well-formed.
As for the single quote ', escaping that is not generally necessary,
only if ' were used as an attribute value delimiter and the attribute
value contains ' itself.

If the ampersand is not escaped in your case them something is wrong.
Not sure what, maybe if you provide some details we can figure it out.
What exactly do you have, a field in a table with text containing an
ampersand like e.g. "Kibo & Xibo", and the WriteXml then does not
generate e.g.
<fieldname>Kibo &amp; Xibo</fieldname>
but rather
<fieldname>Kibo & Xibo</fieldname>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top