Reading XML string using LINQ
By using XDocument.Parse() method we can convert/read xml string to XDocumnet in LINQ. and we can set the xml to gridview as a result set. i.e. we can select the required columns and can assign it to a gridview.
Example:
Design:
Code Behind (C#):
XDocument xdoc = XDocument.Parse(@"
Thomas
Executive
Accounts
5000
Wills
Manager
Accounts
24000
Brod
Manager
Finance
28000
Smith
Analyst
Finance
21000
");
var res = from emp in xdoc.Root.Elements()
select new
{
EmployeeName = emp.Element("Name").Value,
Department = emp.Element("Department").Value,
Salary = emp.Element("Salary").Value
};
gvXML.DataSource = res;
gvXML.DataBind();
Output:
EmployeeName
Department
Salary
Thomas
Accounts
5000
Wills
Accounts
24000
Brod
Finance
28000
Smith
Finance
21000
Useful Tools
Online Code Editor and Compiler
HTML Minifier
Online HTML Compiler/Preivew
Word Count Tool
Replace Text/Word tool
Latest Blogs
How to check if a canvas is empty or blank
Maintain div or panel scroll position after postback in asp.net update panel
Draggable button using jquery ui
Get total number of tables, views, stored procedures and functions count and names in sql server
JavaScript function to get date in mmddyyyy hhmmss ampm forma