Read the XML Using XPath FROM XML Text Reader

 

Copy the below code and call GetXmlNodeValue method to pass on XMLTextReader object and Xpath and get the result.

void GetXmlNodeValue(XmlTextReader reader,string xpathQuery)
        {
            System.Console.WriteLine(“TestOne”);
            XPathDocument xdoc = new XPathDocument(reader);
            XPathNavigator nav = xdoc.CreateNavigator();
            XPathNodeIterator nodeItor = nav.Select(xpathQuery);
             //”STUFF/TYPE1/CENSUS[@COUNTRY=’USA’ and @YEAR=’1930′]/PAGE”);
            nodeItor.MoveNext();
            TraverseSiblings(nodeItor);
            System.Console.WriteLine();
        }

         void TraverseSiblings(XPathNodeIterator nodeItor)
        {
            XPathNodeIterator igor = nodeItor.Clone();
            PrintNode(igor.Current);
            igor.Current.MoveToNext();
            bool more = false;
            do
            {
                PrintNode(igor.Current);
                more = igor.Current.MoveToNext();
            } while (more);
        }

         void PrintNode(XPathNavigator nav)
        {
            System.Console.WriteLine(nav.Name + “:” + nav.Value +
                ” Type : ” + nav.NodeType.ToString());
        }

9 Comments »

  1. 1
    Gokul Says:

    Rock Star!

  2. 2
    Aaron Says:

    Right now it seems like Drupal is the preferred blogging platform
    available right now. (from what I’ve read) Is that what you’re using on your blog?

  3. 3
    Rochelle Says:

    I drop a leave a response each time I especially enjoy a article on a site or I have something to add to the conversation.
    It is triggered by the sincerness displayed in the post I read.
    And on this post Read the XML Using XPath FROM XML Text Reader « .

    Net Heaven. I was actually moved enough to drop a thought 😉 I do
    have a few questions for you if you do not mind.
    Is it simply me or do a few of the comments appear as if they are left by brain dead individuals?
    😛 And, if you are posting at additional sites, I’d like to follow you. Could you list all of your shared pages like your Facebook page, twitter feed, or linkedin profile?

  4. 4
    Harrison Says:

    I comment each time I especially enjoy a article on a site
    or I have something to add to the conversation.
    Usually it’s triggered by the fire communicated in the post I read. And on this article Read the XML Using XPath FROM XML Text Reader « .Net Heaven. I was excited enough to post a thought 🙂 I actually do have 2 questions for you if you don’t mind.
    Could it be simply me or do some of these remarks look like they are coming from brain dead visitors?
    😛 And, if you are posting on other places, I would like to follow everything new you have to post.
    Would you list every one of your communal sites like your linkedin profile, Facebook page or twitter
    feed?

  5. 5

    Hi, Neat post. There’s a problem with your site in web explorer, could test this? IE nonetheless is the market leader and a big section of other folks will pass over your great writing because of this problem.

  6. 6
    Lindsey Says:

    Awesome! Its truly amazing post, I have got much clear idea regarding from this article.

  7. 7
    Dulcie Says:

    certainly like your web site however you have to check the spelling
    on several of your posts. Several of them are rife with spelling issues and I find it very troublesome to tell the reality nevertheless I’ll definitely come back again.

  8. 8
    Kent Says:

    I read this article fully concerning the difference of hottest and previous technologies, it’s awesome article.

  9. magnificent post, very informative. I ponder why the opposite specialists of this
    sector do not understand this. You must continue your writing.
    I’m confident, you’ve a great readers’ base already!


RSS Feed for this entry

Leave a comment