How can get Child Nodes's List from parent Node's Attribute in C# xmldocument

<?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>

I want to get all child nodes on bases of 's attribute.. like if table name Title then xmlchildlist get TID, Title Nodes

Answers


If you are confortable using LINQ, try this:

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];

Need Your Help

MySQL Table does not exist, but it does

mysql database database-design

I am new to building databases, i have created a database for a website i am creating, and i keep getting this message "Executing SQL script in server

How to handle REST calls, data persistence, syncing and observing ContentProvider

android rest android-contentprovider android-syncadapter contentobserver

I know that this question has been asked too many times, but I think the issues I'm trying to target are a little bit different, maybe more complicated.