[英]how to read special nodes from xml and disaplay them on datagridview?
我有一個XML文件,格式如下:
<?xml version="1.0" encoding="utf-8"?>
<Accounts>
<account ID="000">
<UserName>root</UserName>
<Password>root</Password>
<Permission>2</Permission>
</account>
</Accounts>
我只想將ID,用戶名和密碼顯示為DataGridView上的三列。
這可以幫助您:
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();
然后將result
設置為DataGrid
的DataSource
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.