read xml fail

H

haiwen

Hello, every one:

I have a xml file include:

<temperature> 150°F</temperature>

When I use the DataSet's readXML function. I get error
message that ° is an invalid character!

Another problem is how to handle the ... special character
of Word2000 in C#, just like the Tab is \t

Could anyone help?


Best Wishes,

Haiwen
 
J

Jeffrey Tan[MSFT]

Hi Haiwen,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, there is <temperature> 150¡ãF</temperature> in
your xml file, when you use DataSet.ReadXml method to read this xml file,
"invalid character" error generate.

====================
Based on my research, the problem may occur if your xml file was saved with
encoding type: ANSI.
Because your "150¡ãF" characters are Unicode encoded, while stored as ANSI,
you can not read it correctly.

You can try the following Steps/ Solution to see if it helps resolve your
issue:
1). Use NotePad.exe to open your xml file
2). Use "Save As" menu option
3). In the "Save As" dialog box, choose Encoding type: Unicode
4). Save your xml as a new xml file name, such as newxml.xml

Then I think your application can read this xml file correctly(Because .Net
default use Unicode encoding way to read xml file)
Please apply my suggestion above and let me know if it helps resolve your
problem.

====================
For further information, in the xml file's declaration node, you can
specify your xml file's encoding way, such as:
<?xml version="1.0" encoding="UTF-16" ?>

You can use .Net class XmlDeclaration to manipulate the XML declaration
node.
XmlDeclaration has a property Encoding can Gets or sets the encoding level
of the XML document, please refer to:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlDeclarat
ionClassEncodingTopic.asp

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Haiwen,

Thanks very much for your feedback.I am glad it works.

=======================================================
For your further concern of converting Ansi XML file into Unicode encoding
format, I think you can refer to the StreamWriter class whoes constructor
takes one Encoding parameter.

Then, you can pass the StreamWriter to DataSet.WriteXml() method as
parameter.

Sample code like this:

dataSet11.ReadXml("D:\\test.xml");
TextWriter tw=new
StreamWriter("D:\\newtest.xml",false,System.Text.Encoding.Unicode);
dataSet11.WriteXml(tw);

========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Hope you have a nice experience on using Microsoft Newsgroup!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Members online

Forum statistics

Threads
474,090
Messages
2,570,603
Members
47,223
Latest member
smithjens316

Latest Threads

Top