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?
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)
精彩评论