Linq to XML : How to get nested values

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<Config>
<DB>
<tables>
<table>
<table>
</tables>
</DB>
<DB>
<tables>
<table>
<table>
</tables>
</DB>
</Config>

In order to read this I have written following code ... (but it is wrong.... it does not compile)
List<DB> dbList = (from database in doc.Descendants("DB")<br/>
select new DB {<br/>
DatabaseName = database.Attribute("Name").Value,<br/>
ConnectionString = database.Attribute("ConnectionString").Value,<br/>
TableList = (from tables in database.Descendants("Tables")<br/>
select
new GSDataSyncTable {<br/>

TableName = tables.Element("Table").Value<br/>
};
<br/>
};
the idea is to get a list of strongly typed DB objects and each DB Object should contain a list of tables which belong to it.

View the full article
 
Back
Top