Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:44:35+00:00 2026-05-23T14:44:35+00:00

Given a XmlNode containing the following XML fragment, how do I fill XmlNodeList with

  • 0

Given a XmlNode containing the following XML fragment, how do I fill XmlNodeList with book nodes?

XMLNode nodeLibrary contains:

<library>
  <book>
      <title>Three Little Pigs</title>
  </book>
  <book>
      <title>Batman</title>
  </book>
  <address>123 Main St.</address>
  <phone>111-111-1111</phone>
</library>

This should be really easy but I can’t figure it out:

A) Cannot implicitly convert type ‘System.Xml.XmlElement’ to ‘System.Xml.XmlNodeList’:

XmlNodeList books = nodeLibrary[“book”];

I guess the method property shortcut above assumes there’s a SINGLE child named book, not multiple!

B) XmlNode doesn’t have a GetChildren() method:

XmlNodeList books = nodeLibrary.GetChildren(“book”);

C) XmlNode’s ChildNodes property gets ALL children, not just book nodes.

D) I tried using SelectNodes() method but the root is the larger document, not the library fragment in the current XmlNode that was selected from a larger document earlier using SelectNodes.

Any ideas?
Pete

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:44:36+00:00Added an answer on May 23, 2026 at 2:44 pm

    You can use SelectNodes, and in the XPath query pass a ‘.’ to start searching from that node:

    public class StackOverflow_6618097
    {
        const string XML = @"<buildings>
     <library>
      <book>
       <title>Three Little Pigs</title>
      </book>
      <book>
       <title>Batman</title>
      </book>
      <address>123 Main St.</address>
      <phone>111-111-1111</phone>
      <hidden>
       <book>
        <title>The Hidden Treasure</title>
       </book>
      </hidden>
     </library>
     <bookstore>
      <book>
       <title>Cat in the Hat</title>
      </book>
     </bookstore>
    </buildings>";
    
        public static void Test()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(XML);
            XmlNode libraryNode = doc.SelectSingleNode("//library");
            XmlNodeList libraryBooks = libraryNode.SelectNodes(".//book");
            Console.WriteLine("Books: {0}", libraryBooks.Count);
            foreach (XmlNode node in libraryBooks)
            {
                Console.WriteLine(node.OuterXml);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given: a xmlnode that you got from calling the XmlDocument.GetSingleNode method, where you know
Given an XML structure like this: <garage> <car>Firebird</car> <car>Altima</car> <car>Prius</car> </garage> I want to
I have part of XmlDocument Example.xml as given below: <rapaine dotoc=palin domap=rattmin> <derif meet=local
I have the following methods: protected static void updateExistingSection(XmlDocument doc, XmlNode rootNode, string sectionTag,
Given an XML layout like this, I'm trying to create a XSD schema to
Given the following snippet: #include <stdio.h> typedef signed long long int64; typedef signed int
Given the following InsertItemTemplate (simplified) I'm not getting anything back in the event object's
Why can I do the following : Dim qNodes As IQueryable(Of XmlNode) = xDoc.ChildNodes.AsQueryable()
I'm using the following function to put each facility node of my XML in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.