I want to pass the ID as a input parameter of the given xml that will search the XML document for that value within the <id> node.
Once ID found ,I want to find the next node and return it's name as a string.
Given xml as folloing:
<Set>
<Setting>
<Name>username1</Name>
<ID>1234</ID>
<Add>Mumbai</Add>
<Path>name/userdata/img</Path>
</Setting>
<Setting>
<Name>username2</Name>
<ID>4534</ID>
<Add>Navi Mumbai</Add>
<Path>name/userdata/img</Path>
</Setting>
</Settings>
Solution:
This Linq to xml query will return IEnumerbale<string> of value elements, which matched your id. You need to sure ID should be
unquine in given xml.
string value = doc.Descendants("Setting")
.Where(v => (string)v.Element("ID") == Id)
.Select(v => (string)v.Element("Name"))
.SingleOrDefault();
Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts
Monday, August 11, 2014
Read a single node from xml (C# String) in C#/.net
Monday, January 13, 2014
LINQ
What is LINQ?
LINQ stand for Language-Integrated Query. It is new feature introduce in Visual Studio 2008. It has powerful query capabilities to querying on any source of data, data could be sql server database, oracle, collection of objects or xml files. Visual Studio includes LINQ provider assemblies that enable to querying with as given three area.
1.LINQ to Object
2.LINQ to ADO.NET
3.LINQ to XML
LINQ stand for Language-Integrated Query. It is new feature introduce in Visual Studio 2008. It has powerful query capabilities to querying on any source of data, data could be sql server database, oracle, collection of objects or xml files. Visual Studio includes LINQ provider assemblies that enable to querying with as given three area.
1.LINQ to Object
2.LINQ to ADO.NET
3.LINQ to XML





