Parsing xml files in windows phone 7

北战南征 提交于 2020-01-06 15:06:47

问题


i have the following xml file

<entry>
<math marks>45</math marks>
<eng marks>67</eng marks>
<phy marks>56</phy marks> 
</entry>

i wish to parse this xml file in windows phone 7 such that i can extract the values for each tag, for example math marks has value 45, and save them in a variable of type double and perform some mathematical operations on the created variable.

How can i do this?


回答1:


Firstly, that isn't xml (element names can't have whitespace). It would have to be, for example:

<entry>
<mathmarks>45</mathmarks>
<engmarks>67</engmarks>
<phymarks>56</phymarks> 
</entry>

XDocument is supported on WP7 (MSDN), so you should be able to use:

var entry = XDocument.Parse(xml);
int math = (int)entry.Element("mathmarks");
int eng = (int)entry.Element("engmarks");
int phy = (int)entry.Element("phymarks");

Another option is XmlSerializer, also supported on WP7 (MSDN)



来源:https://stackoverflow.com/questions/5610258/parsing-xml-files-in-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!