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 8173707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:13+00:00 2026-06-06T22:15:13+00:00

<Root> <P1 Text =A > <P2 Text = AA> <P3 Text = AAA> <L

  • 0
<Root>
  <P1 Text ="A" >
    <P2 Text = "AA">
      <P3 Text = "AAA">
        <L Text = "l_A"/>
        <L Text = "l_B"/>
        <L Text = "l_C"/>
      </P3>
      <P3 Text = "BBB">
        <L Text = "l_D"/>
        <L Text = "l_E"/>
        <L Text = "l_F"/>
      </P3>
    </P2>
    <P2 Text = "BB">
       <L Text = "l_G"/>
       <L Text = "l_H"/>
       <L Text = "l_I"/>
    </P2>
  </P1>
</Root>  

From an XML document containing thousands of variably nested nodes up to 10 levels deep, I
would like to retrieve programmatically only the leaves belonging to any of the “P” parents
as follows: for instance, in the example above, selecting P2 “AA” would yield l_A to l_F and P3 “BBB” would give l_D to l_F.

  • 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-06T22:15:14+00:00Added an answer on June 6, 2026 at 10:15 pm

    Something like this (returns a list of strings):

        XDocument doc = XDocument.Load(@"test.xml");
    
        string level = "P3";
        string levelAttr = "AAA";
    
        var list = (from d in doc.Descendants(level)
                    let xAttribute = d.Attribute("Text")
                    where xAttribute != null && xAttribute.Value == levelAttr
                    from l in d.Descendants("L")
                    let lAttribute = l.Attribute("Text")
                    where lAttribute != null
                    select lAttribute.Value);
    

    You may remove the attribute null checks if the Text attribute is always there…

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

Sidebar

Related Questions

Something like this: from Tkinter import * root = Tk() but = Button(root, text
My XML: <root> <child> <childOfChild> <anotherLostChild> <currentSelectedNode> SOME TEXT </currentSelectedNode> </anotherLostChild> </childOfChild> </child> </root>
I have the following input XML: <root age=1> <description>some text</description> <section> <item name=a> <uuid>1</uuid>
I'm trying to get only elements that have text, ex xml : <root> <Item>
One page in my root directory, displays text collected from the database. This page
I have the following PHP script : <?php header('Content-type: text/xml'); mysql_connect('localhost', 'root', 'root'); mysql_select_db('sportApp');
I have some XML thus <root> <TemplateNode> <Heading> <ID>1</ID> <Name>HeadingNodeTest</Name> <Order>1</Order> <Text>This is a
I have a list of directories starting from /root. Eg random text /root/dir1/files random
I have the following code. from xml.dom.minidom import Document doc = Document() root =
How to select items whose sub-tag key's text starts with '001'? <root> <item> <key>001001</key>

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.