connectseekers.com

Wednesday, 5 August 2020

How to get value from XML using Linq in C#?

8/05/2020 - By Pranav Singh 0

How to get value from XML using Linq in C#. This article will show you how you can read an XMl node using c#.net. this code you can use in your asp.net, mvc application.

So here is you XML file .

<?xml version="1.0" encoding="utf-8" ?>

<root>

  <node1>Node 1 Value</node1>

  <node2>Node 2 Value</node2>

  <node3>Node 3 Value</node3>

  <node4>Node 4 Value</node4>

</root>

 Now check the code. In this code I have accessed the node 3 value using linq in c#.net.

 

string xmlFilePath = @"\App_Data\Node.xml";

            XDocument _xdocument = XDocument.Load(Server.MapPath(xmlFilePath));

            var xmlNnode = _xdocument.Descendants().Where(n => n.Name == "node3").FirstOrDefault();

            string nodeValue;

            if (xmlNnode != null)

            {

                nodeValue = xmlNnode.Value;

            }

 The above code is for asp.net or other web application. Now apply the break point and check the output.

xml node

Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top