my xml is below:
<Demo>
<ClientCompanyId CompanyId="1">
<MyMenu>
<module MenuType="0" ModID="Mod1" ModuleID="1" Perm="False" Text="Basic Settings">
<menu MID="1-1" MenuDescription="Mod" MenuType="0" ModuleID="1" ParentID="Mod1" Perm="False" Text="Forms">
<Leaf LeafNode="true" MID="1-3" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-3" ParentID="1" Perm="False" TargetUrl="" Text="LookUp"/>
<submenu MID="1-4" MenuDescription="" MenuType="0" ModuleID="1" ParentID="1" Perm="False" Text="Bank Branch">
<Leaf LeafNode="true" MID="1-5" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-5" ParentID="4" Perm="False" TargetUrl="" Text="BO Category"/>
</submenu>
</menu>
<menu MID="1-2" MenuDescription="Mod" MenuType="0" ModuleID="1" ParentID="Mod1" Perm="False" Text="Reports">
<Leaf LeafNode="true" MID="1-6" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-6" ParentID="2" Perm="False" TargetUrl="" Text="Cheque Type"/>
<Leaf LeafNode="true" MID="1-7" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-7" ParentID="2" Perm="False" TargetUrl="" Text="Stock Exchange"/>
</menu>
</module>
</MyMenu>
</ClientCompanyId>
</Demo>
my linq syntax is below:
XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");
var q = from c in loaded.Descendants("module")
where (int)c.Attribute("ModuleID") < 0
select (string)c.Attribute("Text");
From the above xml file i want to get tag attributes values.
Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False"
From the above xml i want to get all tag attributes values .
How to get value from an xml file?
Or you can in the last step cast to XElement and use whatever XElement has to offer:
instead of var q:
if you know one record is going to be return
UPDATE
to make further queries to your result:
then loop foreach, you can use
menuselement.Element("tag_name").Valueto get string values of the nodes, ormenuselement.Attribute("attr_name").Valueto get attribute values, and you can further query with menuslement.Find ormenuselement.Whereormenuselement.Selectand the options are really limitless… here is where you can learn more:http://msdn.microsoft.com/en-us/library/bb387065.aspx
And here is MSDN’s how to query xml using linq:
http://msdn.microsoft.com/en-us/library/bb943906.aspx