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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:36:03+00:00 2026-05-15T14:36:03+00:00

These two LINQ to XML methods seem to be doing the same thing. Would

  • 0

These two LINQ to XML methods seem to be doing the same thing. Would like to know the difference between the two.

var xdoc = XDocument.Load(filename);

xdoc.Root.FirstNode.ElementsAfterSelf();
xdoc.Root.FirstNode.NodesAfterSelf();

Both return methods return

<Title Name="Cooking with Computers: Surreptitious Balance Sheets" Price="11.9500">
  <Authors>
    <Author Name="O'Leary, O'Leary" />
    <Author Name="MacFeather, MacFeather" />
  </Authors>
</Title>  
<Title Name="You Can Combat Computer Stress!" Price="2.9900">
  <Authors>
    <Author Name="Green, Green" />
  </Authors>
</Title>  

Here is the XML

<PubsDatabase>
  <Title Name="The Busy Executive's Database Guide" Price="19.9900">
    <Authors>
      <Author Name="Green, Green" />
      <Author Name="Bennet, Bennet" />
    </Authors>
  </Title>
  <Title Name="Cooking with Computers: Surreptitious Balance Sheets" Price="11.9500">
    <Authors>
      <Author Name="O'Leary, O'Leary" />
      <Author Name="MacFeather, MacFeather" />
    </Authors>
  </Title>
  <Title Name="You Can Combat Computer Stress!" Price="2.9900">
    <Authors>
      <Author Name="Green, Green" />
    </Authors>
  </Title>
</PubsDatabase>
  • 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-15T14:36:04+00:00Added an answer on May 15, 2026 at 2:36 pm

    Nodes will return things like text nodes as well as elements, basically. For example:

    using System;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace Test
    {
        class Test
        {
            static void Main()
            {
                XElement element = new XElement("root",
                    new XElement("child1", "text1"),
                    "text directly in root",
                    new XElement("child2"),
                    new XElement("child3", "text3"));
    
                XElement child1 = element.Element("child1");
                var nodes = child1.NodesAfterSelf();
                foreach (var node in nodes)
                {
                    Console.WriteLine(node.NodeType);
                }
            }
        }
    }
    

    This prints

    Text
    Element
    Element
    

    A few things to note:

    • It’s not including the nodes within itself
    • It’s not recursing (it doesn’t show the text node of child3)
    • It does include the text node directly after it, which ElementsAfterSelf wouldn’t.

    As a side note, attributes don’t count as nodes in LINQ to XML. From the XNode documentation:

    Represents the abstract concept of a
    node (one of: element, comment,
    document type, processing instruction,
    or text node) in the XML tree.

    This is in contrast to most XML APIs.

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

Sidebar

Related Questions

Is there any difference between these two LINQ statements: var query = from a
These two methods appear to behave the same to me public IEnumerable<string> GetNothing() {
So these two methods have the same signature but different constraints public static void
Is LINQ to Dataset subset of LINQ to EF or these two are independent?
These two querys gives me the exact same result: select * from topics where
Do these two statements pass the same type of argument (a Hash) to the
If these two methods are simply synonyms, why do people go to the trouble
I am querying an HTML file with LINQ-to-XML. It looks something like this: <html>
I would like to get the two attribute-assignment lines below into one line since
Book uses different terms for Linq-to-XML methods/properties defined in classes XObject , XNode ,

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.