Menu Home

how to get a xml node value

We have a XML file like this :

<?xml version=”1.0″ encoding=”us-ascii”?>
<author>Lebel, L.; Anderies, J.M.; Campbell, B.M.; Folke, C.; Hatfield-Dodds, S.; Hughes, T.P.; Wilson, J</author>
<title>Governance and the capacity to manage resilience in regional social-ecological systems</title>

I am using C# here…
Let say we want to get the value of author node.. In order to get the author node value, we need to do this three steps.
First, we have to Load the XML file.. and then address the author node.. then read the node value into a string. The code should be like this…

using System.Xml;
using System.Text;

XmlDocument doc=new XmlDocument();

XmlNode authorNode = doc.SelectSingleNode(“Publications/PubDetail/author/text()”);
string metaCreator = authorNode.Value;

Response.Write(“Author : ” + metaCreator);

Categories: c# Internet Komputer Programming


Software Engineer, Blogger, Internet Savvy, Tech Enthusiast