XMLDocument not able to locate a node - SelectSingleNode

Posted on 2009-12-21
Last Modified: 2012-05-08
I have simple XML file. I need to read the value of the element <totalresults>.
Please see code below, it never seems to locate that node. What is wrong with this?

Please help.

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







C# Code


XmlNode node=xmldoc.SelectSingleNode("//totalresults");

if (node != null)

  return node.InnerText;


  return "0";

Open in new window

Question by:codemonkey2480
    1 Comment

    Accepted Solution

    Found the solution:

    The C#/xpath below would grab totalresults element

    Further reading:

    XmlNode node = xmldoc.SelectSingleNode("descendant::feed").FirstChild;
                if (node != null)
                    return node.InnerText;
                    return "0";

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now