<?xml version="1.0" encoding="utf-8" ?>
<Database name="DB1">
<Table name="Faculty">
<Column>FID</Column>
<Column>First Name</Column>
<Column>Last Name</Column>
<Column>DOB</Column>
<Column>Phone No</Column>
<Column>Full Address</Column>
<Column>Salary</Column>
<Column>Heights</Column>
</Table>
<Table name="Title">
<Column>TID</Column>
<Column>Title</Column>
</Table>
</Database>
我想基于's属性获取所有子节点..就像表名称标题然后xmlchildlist获取TID,标题节点
答案 0 :(得分:0)
如果您习惯使用LINQ,请尝试以下方法:
var name = "Title";
XDocument doc = XDocument.Load(path);
var selectors = (from elements in doc.Elements("Database").Elements("Table")
where elements.Attribute("name").Value == name
select elements).FirstOrDefault();
var list = selectors.Elements("Column").ToList();
var id = list[0];
var title = list[1];