I have an xml file whitch has the format like below:
<?xml version="1.0" encoding="utf-8"?>
<Accounts>
<account ID="000">
<UserName>root</UserName>
<Password>root</Password>
<Permission>2</Permission>
</account>
</Accounts>
I just want to display the ID, UserName and Password as three columns on DataGridView.
This may helps you:
System.Xml.Linq.XDocument doc = XDocument.Load(YOUR XML FILE PATH);
var result = doc.Element("Accounts").Elements("account").Select(i => new
{
Id = i.Attribute("ID").Value,
User = i.Element("UserName").Value,
Pass = i.Element("Password").Value
}).ToList();
Then set the result
as the DataSource
of your DataGrid
.
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.