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

  • SEARCH
  • Home
  • 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 8020851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:48:27+00:00 2026-06-04T21:48:27+00:00

I am trying to extract certain values from an xml document. In the example

  • 0

I am trying to extract certain values from an xml document. In the example below, I want to store the values stored in the ‘c’ and ‘d’ nodes in a list, but only where the ‘b’ node contains both ‘c’ AND ‘d’. The code I have so far loops through all of the ‘b’ nodes, but I am uncertain what to put in the while loop, or if this is the best approach.

XmlDocument attrsXML = new XmlDocument();
attrsXML.LoadXml(dbReader["SampleXml"].ToString());

XPathNavigator nav = attrsXML.CreateNavigator();

XPathNodeIterator attribNodes = nav.Select("/a/b");

while (attribNodes.MoveNext())
{
    // What do I need to put here in order to extract the 'c' and 'd' nodes?
    // Any other nodes can be ignored (such as 'e' above). I am only interested
    // when 'b' contains both 'c' AND 'd'.
}

Where ‘SampleXml’ loaded from the database is:

<a>
    <b>
        <c>Extract this</c>
        <d>And this</d>
        <e>not this</e>
    </b>
    <b>
        <c>not this</c>
        <e>not this</e>
    </b>
    <b>
        <c>Extract this</c>
        <d>And this</d>
    </b>
</a>

Any help appreciated.

  • 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-06-04T21:48:29+00:00Added an answer on June 4, 2026 at 9:48 pm

    You can use the following code:

    XmlDocument attrsXML = new XmlDocument();
    attrsXML.LoadXml(dbReader["SampleXml"].ToString());
    
    
    XmlNodeList nodeList = attrsXML.SelectNodes("/a/b[c and d]");
    
    foreach (XmlNode xmlNode in nodeList)
    {
      string cText = xmlNode.SelectSingleNode("c").InnerText;
      string dText = xmlNode.SelectSingleNode("d").InnerText;
    }
    

    The XPath “/a/b[c and d]” returns all b elements which contain c and d elements as children, which means you don’t need to check it inside the loop manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse an XML to extract values of certain variables. Here's
I'm trying to extract about 72000 SInt32s from the iPhone, but not sure what
hi i'm trying to extract values from this tagged file here is the file
I'm trying to extract some information from an xml file using xslt. I've used
I'm trying to filter certain data from an HTML file. For example, the HTML
I want to extract information from three tables which are linked by certain ids
I have a database from which I am trying to extract certain information. The
I have a datatable that I want to extract certain information from (only certain
Hey Im trying to extract certain information from a string. The String looks like
i am trying to extract xml element by name and below code does work

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.