請如何閱讀下面的xml字符串。如何解析Windows Phone 7中的xml字符串?
<NewDataset>
<Table>
<Id>1</Id>
</Table>
</NewDataset>
我需要得到id .please告訴我。
請如何閱讀下面的xml字符串。如何解析Windows Phone 7中的xml字符串?
<NewDataset>
<Table>
<Id>1</Id>
</Table>
</NewDataset>
我需要得到id .please告訴我。
Windows 7手機支持大部分C#,因此您可以像使用其他C#代碼一樣使用所有相同的方法來解析XML。查找XmlDocument或XDocument。
here is a full tutorial reference給你。使用這段代碼
string xmlData =
@"<ServiceReply>
<StockQuote symbol='IBM' price='32.50' quotetime='01/01/2010 12:21:00'/>
<StockQuote symbol='MSFT' price='21.20' quotetime='01/01/2010 12:20:30' />
</ServiceReply>
";
:C#代碼解析這個XML
var quotes = from quote in dataDoc.Descendants("StockQuote")
let stamp = DateTime.Parse(quote.Attribute("quotetime").Value)
orderby stamp ascending
select new StockQuote
{
Symbol = quote.Attribute("symbol").Value,
Price = decimal.Parse(quote.Attribute("price").Value)
};
讓我們知道,如果它的工作原理。希望有幫助
var id = Convert.ToInt32(XDocument.Parse(xml).Root.Element("id").Value);