Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Multi Level Descendants

Multi Level Descendants

Scheduled Pinned Locked Moved LINQ
xmlquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adriaan Davel
    wrote on last edited by
    #1

    Hi, I have recursive XML (an object containing 1 or more instances of his own type) and I want to get the Descendants of my current node but exclude the sub-nodes, how would I do that? Here's my XML:

    <BodyItem>
    <Fields>
    <Field Name="Second 1" >1</Field>
    <Field Name="Second 2" >2</Field>
    </Fields>
    <BodyItems>
    <BodyItem >
    <Fields>
    <Field Name="Field3" IsReadOnly="false"></Field>
    </Fields>
    </BodyItem>
    </BodyItems>
    </BodyItem>

    From the above XML I would like to get Fields "Second 1" and "Second 2", but exclude "Field3"

    ____________________________________________________________ Be brave little warrior, be VERY brave

    A 1 Reply Last reply
    0
    • A Adriaan Davel

      Hi, I have recursive XML (an object containing 1 or more instances of his own type) and I want to get the Descendants of my current node but exclude the sub-nodes, how would I do that? Here's my XML:

      <BodyItem>
      <Fields>
      <Field Name="Second 1" >1</Field>
      <Field Name="Second 2" >2</Field>
      </Fields>
      <BodyItems>
      <BodyItem >
      <Fields>
      <Field Name="Field3" IsReadOnly="false"></Field>
      </Fields>
      </BodyItem>
      </BodyItems>
      </BodyItem>

      From the above XML I would like to get Fields "Second 1" and "Second 2", but exclude "Field3"

      ____________________________________________________________ Be brave little warrior, be VERY brave

      A Offline
      A Offline
      Adriaan Davel
      wrote on last edited by
      #2

      I think I have found the answer (so soon :-D ), this worked for me, is it the correct way?

      var fields = (from bif in bodyItemNode.Elements("Fields").Descendants("Field")

      ____________________________________________________________ Be brave little warrior, be VERY brave

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups