how to get a xml node value

We have a XML file like this :

<?xml version=”1.0″ encoding=”us-ascii”?>
<Publications>
<PubDetail>
<idPub>2149</idPub>
<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>
<journal_volume>11</journal_volume>
<journal_number>1</journal_number>
<language>english</language>
<record_type>Articles</record_type>
</PubDetail>
</Publications>

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();
doc.LoadXml(UnicodeEncoding.UTF8.GetString(data));

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

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

ariawan

Web Developer, Blogger, Internet Savvy, Tech Enthusiast

You may also like...