Question

I am trying to access a webpage that has BIG5 encoding paragraph. After retrieving the xml data, I use XMLRead.Create(new StringReader(xmldata)) and get the big5 characters from reader.Value of XmlNodeType.Text type. In WP runtime, it does not support BIG5 encoding so I have to get each byte and convert to unicode for display on WP7. However, the byte I get the from reader.Value seems not what I expected. For example, the first Chinese character is B5E1. But I got FDFD. What's wrong is that?

using (XmlReader reader = XmlReader.Create(new StringReader(xmldata)))  
while (reader.Read())  
    switch (reader.NodeType)  
        case XmlNodeType.Text:
            string s = reader.Value;  
            foreach (byte input in s)  
                # the input gives unexpected result  

The webpage to load is http://feeds.feedburner.com/nownews/politic

I am using VS2010 for WP7 development work.

Any help is appreciated!

Was it helpful?

Solution

Windows Phone SDK doesn't support BIG5 encoding, but if you need it, just go ahead and generate the encoding class with the Silverlight Encoding Generator.

OTHER TIPS

An encoding defines how a byte stream is translated into a .Net string. Since you cannot apply the BIG5 encoding, .Net will choose either a default encoding or the one given in the XML file.

The result is that as you parse the XmlReader, the translation bytes=>string has already taken place, and the foreach(byte in string) iterates over the .Net representation of the wrongly translated string.

I have not worked with these parts of the API, but it seems that the XmlReader methods mentioned here are the ones to retrieve the original byte stream behind an XML node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top