dataset.writeXml

  • Thread starter Christina Androne
  • Start date
C

Christina Androne

Hello

I am using the dataset.WriteXml method to convert a dataset's content to
an XML string which will be parsed later on. I initally used WriteXml
with a stream parameter, then got the string representing the XML from
it. The problem was that special characters, such as currency symbols,
are not escaped in the final string. So of course later on trying to XML
parse that string fails.
I also used an XmlTextWriter as the WriteXml parameter, then obtained
the XML string from xmlTextWriter.BaseStream. Special chars are still
not escaped.

Can anybody put me on the right track with this?

Thank you,
Christina Androne
 
N

Nicholas Paldino [.NET/C# MVP]

What do you mean special characters are not escaped? If you produce the
XML from the data set, then it should load up fine when you pass that back
to a data set.

You mention special characters. Can you show the output of one of your
calls to write xml? Also, if you are writing to a string, why not use a
StringWriter, and then get the string to pass around.

Also, is there an encoding issue here? Is it possible that you have
data that is not being encoded correctly (unicode chars and ascii encoding
perhaps)?

Hope this helps.
 
C

Christina Androne

Nicholas said:
What do you mean special characters are not escaped? If you produce the
XML from the data set, then it should load up fine when you pass that back
to a data set.

It only happends when I am producing XML from a dataset with a currency
symbol column, which contains items such as £.
You mention special characters. Can you show the output of one of your
calls to write xml? Also, if you are writing to a string, why not use a
StringWriter, and then get the string to pass around.

(ods is OracleClientDataset)

I used to use this:

System.IO.StringWriter sw = new System.IO.StringWriter();
ods.WriteXml(sw, XmlWriteMode.WriteSchema);
string s = sw.ToString();
sw.Close();
ods.Clear();


And then I replaced with this:


XmlTextWriter xw = new XmlTextWriter(ms, System.Text.Encoding.Unicode);
ods.WriteXml(xw, XmlWriteMode.WriteSchema);
StreamReader sr = new StreamReader(xw.BaseStream, true);


hoping that £ will be output as £ or to whatever escaping sequence
that is correct (as I am not sure if this is the one)

Basically, from a column such as this:

SYMBOL
£


I need a string such as

"<ELEMENT>
<SYMBOL>£</SYMBOL>
</ELEMENT>
<ELEMENT>
<SYMBOL>€</SYMBOL>
</ELEMENT>"

What I am getting now is:

"<ELEMENT>
<SYMBOL>£</SYMBOL>
</ELEMENT>
<ELEMENT>
<SYMBOL>€</SYMBOL>
</ELEMENT>"

This last one fails because of the currency symbols (for the skeptics,
I've removed them to test if XML is valid without them, it is).
Also, is there an encoding issue here? Is it possible that you have
data that is not being encoded correctly (unicode chars and ascii encoding
perhaps)?

I don't know the answer to that one; except for the second example I am
not specifying any encoding anywhere (assuming unicode is default). If
it's not too much to ask, can you point me where I could check for
having the right encoding?

Thank you,
Christina Androne
 

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