简体   繁体   中英

Get string form XML file by attribute

I have a XML file

<resources>
  <string name="aaa">Hotel</string>
  <string name="bbb">Home</string>
  <string name="ccc">Castle</string>
  ...
<resourses>

I tried got content string (Hotel or Home ...) in using special name of this (aaa, bbb ..).

var xml = XDocument.Parse(yourxmlstring, LoadOptions.None);
var resources= xml.Descendants("resources");
foreach (var resourceElement in resources.Descendants("Hotel"))
{
    MessageBox.Show(resourceElement.Attribute("name").Value);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM