Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > read xml fail

Reply
Thread Tools

read xml fail

 
 
haiwen
Guest
Posts: n/a
 
      01-15-2004
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

 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-16-2004

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...XmlXmlDeclarat
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.

 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-21-2004

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.E ncoding.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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux (Ubuntu) fail. A LONG read. Max Burke NZ Computing 68 10-02-2009 12:36 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
perl scripts fail to read commandline arguments reeddeer Perl Misc 5 03-13-2005 12:26 AM
if (f() != FAIL) or if (FAIL != f())? Wenjie C Programming 3 07-31-2003 09:54 PM
xml file write fail??? haiwen ASP .Net Web Controls 2 07-22-2003 09:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57