1

Here I am listing an xml.

<?xml version="1.0" encoding="utf-8" ?>
<data>
    <dataitem>
        qqqqqqq
    </dataitem>
    <templatedata>
        <Year>2001</Year>
    </templatedata>
    <mailmergedata>
        <row>
            <facilityname>ABC Corporation</facilityname>
            <dueamount>200.00</dueamount>
        </row>
        <row>
            <facilityname>XYZ Corporation</facilityname>
            <DueAmount>50.00</DueAmount>
        </row>
    </mailmergedata>
</data>

I want to retrive the value of the node facilityname Anybody pls help

Rais Alam
  • 6,970
  • 12
  • 53
  • 84
Krishnan
  • 1,030
  • 1
  • 15
  • 30

2 Answers2

1

try this:

XDocument xmlFile = XDocument.Load("xml file path");
var query = from c in xmlFile.Descendants("facilityname ") select c;

then

foreach (XElement element in query)
{
    Console.WriteLine(element); // get your value here
}

Refer Job Skeet's answer, that may help you ..

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
1

You can also use XPathSelectElements and then use XPath to navigate:

xdoc.XPathSelectElements("/data/mailmergedata/row/facilityname")
StuartLC
  • 104,537
  • 17
  • 209
  • 285