0
<?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 属性的所有子节点.. 比如如果表名 Title 然后 xmlchildlist 获取 TID,Title Nodes

4

1 回答 1

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];
于 2012-06-17T06:09:05.573 回答