Skip to main content
 首页 » 编程设计

c#之在 Windows Phone 中解析 XML 文件

2024年02月13日23lonelyxmas

我有来自 Android 的 XML,我想在我的 Windows Phone 项目中解析它。我只能获取元素名称的值,但我需要更深入地获取:

  • 波尔斯基
  • szt ml

C#:

foreach (XElement level1Element in XElement.Parse(loadedStringXml).Descendants("string")) 
{ 
    myText = level1Element.Attribute("name").Value; 
} 

还有我的 XML 文件

<?xml version="1.0" encoding="utf-8"?> 
<resource> 
  <string name="CurrentLanguage">Polski</string> 
  <string-array name="myTypes"> 
    <item>szt</item> 
    <item>ml</item> 
  </string-array> 
</resource> 

请您参考如下方法:

要获取 Polski,请使用 levle1Element.Value。 要获取 szt 和 ml,请使用:

foreach (var item in level1Element.Descendants("item")) 
    item.Value; // this contains szt and ml