전체 Windows Phone 7 앱을 만들었지 만 자랑 스럽습니다.하지만 내 웹 사이트에서 내 앱에 액세스 할 수있는 XML 파일의 실제 용도가 없다는 것을 깨달았습니다. . 업데이트가 필요 없기 때문에 단순히 프로젝트의 일부로 포함하는 것이 훨씬 더 합리적이라고 판단했습니다. 그러나, 내가 배운 경험과 튜토리얼의 대부분은 XML 데이터를 WebClient를 통해 다운로드 한 후 목록 상자로 파싱하는 방법을 보여주었습니다. 따라서 WebClient를 오프라인 XML 로더로 대체하는 쉬운 방법이 있습니까?WebClient를 오프라인 XDocument로 바꾸기
이것은 본질적으로 내 앱에서 몇 페이지를 코딩했는지, 분명히 내 앱의 목적과 관련된 일부 이름을 사람/이름/나이에 대해 말도 안되게 변경 한 것입니다.
namespace WindowsPhoneApplication14.Pages.Other
{
public partial class People : PhoneApplicationPage
{
public People()
{
InitializeComponent();
Dispatcher.BeginInvoke((Action)(() => pplListBox.ItemsSource = ppldata));
WebClient pplWebClient = new WebClient();
pplWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ppl_DownloadStringCompleted);
pplWebClient.DownloadStringAsync(new Uri("http://www.mywebsite.com/ppl.xml"));
}
void ppl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XElement xmlitem = XElement.Parse(e.Result);
var ppldata = new List<PeopleClass>();
foreach (XElement item in xmlitem.Elements("entry"))
{
var name = item.Element("name");
var namevalue = (name == null) ? null : name.Value;
var age = item.Element("age");
var agevalue = (age == null) ? null : age.Value;
ppldata.Add
(new PeopleClass
{
Name = namevalue,
Age = agevalue,
}
);
}
pplListBox.ItemsSource = ppldata;
}
public class PeopleClass
{
public string Name { get; set; }
public string Age { get; set; }
}
public System.Collections.IEnumerable ppldata { get; set; }
}
}
그래서 WebClient 작업을 어떻게 바꿀 수 있습니까?
다시 한 번 감사드립니다, 믹. 나는 최대한 빨리 이것을 시도 할 것이다. – Dan
YW : ../15char –