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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:38:02+00:00 2026-06-15T03:38:02+00:00

I have this xml: <root> <sub>maintext1 <subsub>subtext1</subsub> <subsub>subtext2</subsub> </sub> </root> I initially tried <

  • 0

I have this xml:

    <root>      
      <sub>maintext1
        <subsub>subtext1</subsub>
        <subsub>subtext2</subsub>
      </sub>          
    </root>

I initially tried < sub>.Value, but this returned everything inside the sub, then < sub>.ToString which does the same thing. I searched for a solution but everywhere was used the xmlElement.InnerText but I need it for xElement which isn’t available. How can I use the inner text property for the xElement?

  • 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-15T03:38:03+00:00Added an answer on June 15, 2026 at 3:38 am

    You can get all the nodes of an XElement of a specific type by using the OfType Linq extension on the return value of the Nodes method.

    XElement.Nodes().OfType<XText>()
    

    This example gets the value you’re looking for, I think:

    var xml = 
        @"<root>      
           <sub>maintext1
            <subsub>subtext1</subsub>
            <subsub>subtext2</subsub>
           </sub>          
          </root>";
    var xel = XElement.Parse(xml);
    var textNodes = xel.Element("sub").Nodes().OfType<XText>();
    var mainText1 = textNodes.First().Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML: <root> <items> <item1> <tag1>1</tag1> <sub> <sub1>10 </sub1> <sub2>20 </sub2> </sub>
Suppose I have this XML document... <root> <str name=My node's attribute>My string's value</str> </root>
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
I have a RelativeLayout with one child as <include another.xml> like this root.xml :
It seems I can't easily have an XSD declaration for this simple XML <root>
I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
Hi I have an xml document like this <root> <cert id=1> </cert> <cert id=2>
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
I have the following XML <ns0:Root xmlns:ns0=http://Map_Sample.Input_Schema> <Number1> </Number1> <Number2>11</Number2> <Number3>12</Number3> </ns0:Root> In this
I have this xml from which I am trying to grab the value 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.