public partial class MainPage: PhoneApplicationPage
{
HttpWebRequest request = null;
HttpWebResponse response = null;
/ / constructor
public MainPage ()
{
InitializeComponent ();
string uri = "http://fpad.ce.cn/hg/news_list.xml" ;
request = (HttpWebRequest) WebRequest.Create (uri);
request.Method = "POST";
request.BeginGetResponse (new AsyncCallback (GetResponseCallBack), null);
}
private void GetResponseCallBack (IAsyncResult ar)
{
List
response = (HttpWebResponse) request.EndGetResponse (ar);
using (Stream stream = response.GetResponseStream ())
{
StreamReader reader = new StreamReader (stream, new ; Gb2312Encoding ());
using (XmlReader xmlReader = XmlReader.Create ( reader))
{
string title = ; " " ;
string intro = ; " " ;
while (xmlReader.Read ( ) )
{
try
{
if (xmlReader.ReadToFollowing ("a"))
{
title = xmlReader.ReadElementContentAsString ();
}
if (xmlReader.ReadToFollowing ("summary"))
{
intro = xmlReader.ReadElementContentAsString ();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString ());
}
if (title = "!" | |! intro = "")
{
newList.Add (new News {Title = title, Intro = intro});
}
}
} ;
}
Dispatcher.BeginInvoke (() =>
{
NewsList.ItemsSource = newList;
});
}
}
class News
{
public string Title {set; get;}
public string Intro {set; get;}
}
Whatever the title is , every single step debugging to third on the error, that is to say in the first two xml data can be read successfully , the third if (xmlReader.ReadToFollowing (" ; a ")) was catch the
------ Solution ------------------------------- -------------
requirements hexadecimal , but you enter yes.
therefore invalid.
------ eference --------------------------------------- < br> throw anything unusual ?
------ eference --------------------------------------- < br>
------ eference ----- ----------------------------------
then you should look at my code how to change it .
Also, I use a lot of ways ,
these two approaches , which implementation will do, but I have given, Could you help me find in the end the problem lie
------ eference -------- -------------------------------
XDocument.Load (uri) to load the url references XDocument new files . This file is located in the application's XAP package. If you download a file from some other location , see : http://msdn.microsoft.com/zh-cn/library/cc645034 (v = vs.95) aspx..
------ eference --------------------------------------- < br>
issues that may arise in the StreamReader reader = new StreamReader (stream, new Gb2312Encoding ());
use GB2312Encoding encoding.
------ eference ------------------------------------ ---
but xml document gb2312, wp not support gb2312, so only use a third party to turn
------ eference ------------- --------------------------
by the way, I have two dll references, but still the same error
------ eference --------------------------------------- < br> All of the problems are because wp does not support gb2312, find a code library , very good find . There are similar problems to me it
没有评论:
发表评论