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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:05:25+00:00 2026-05-15T20:05:25+00:00

How to get a value of XElement without getting child elements? An example: <?xml

  • 0

How to get a value of XElement without getting child elements?

An example:

<?xml version="1.0" ?>
<someNode>
    someValue
    <child>1</child>
    <child>2</child>
</someNode>

If i use XElement.Value for <someNode> I get "somevalue<child>1</child><child>2<child>" string but I want to get only “somevalue” without "<child>1</child><child>2<child>" substring.

  • 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-15T20:05:26+00:00Added an answer on May 15, 2026 at 8:05 pm

    You can do it slightly more simply than using Descendants – the Nodes method only returns the direct child nodes:

    XElement element = XElement.Parse(
        @"<someNode>somevalue<child>1</child><child>2</child></someNode>");
    var firstTextValue = element.Nodes().OfType<XText>().First().Value;
    

    Note that this will work even in the case where the child elements came before the text node, like this:

    XElement element = XElement.Parse(
        @"<someNode><child>1</child><child>2</child>some value</someNode>");
    var firstTextValue = element.Nodes().OfType<XText>().First().Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll need to modify this based on your needs, but… May 17, 2026 at 1:34 am
  • Editorial Team
    Editorial Team added an answer I've did it with DocumentRoot: DocumentRoot *site*/index.php It generates warning,… May 17, 2026 at 1:34 am
  • Editorial Team
    Editorial Team added an answer You only have 30 seconds to produce finish execution and… May 17, 2026 at 1:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to get all nodes from an XElement that actually has a value,
When I use the following code I get the same items multiple times. XElement
I am trying to write a query expression to parse an XML tree, but
I have an XElement and inside that element I have another XML fragment. How
here is my problem I have the following array (for example) string[] arr =
I would like to traverse every element and attribute in an xml and grab
I have an xml that I am querying. One of the nodes is missing.
XElement config = XElement.Parse( @<Response SessionId='BEDF38F9ADAB4F029404C69E49951E73' xmlns='http://schemas.sample.com/sample.xsd'> <Status Success='true' Message='User is now logged in.'
` XElement config = XElement.Parse ( @<Response SessionId='426D9AEB1F684849A16D79A6CF48582B' xmlns='http://schemas.tmaresources.com/timssws60.xsd'> <Status Success='true' Message='Connected' ErrorCode='0' />
Consider the following XML: <response> <status_code>200</status_code> <status_txt>OK</status_txt> <data> <url>http://bit.ly/b47LVi</url> <hash>b47LVi</hash> <global_hash>9EJa3m</global_hash> <long_url>http://www.tumblr.com/docs/en/api#api_write</long_url> <new_hash>0</new_hash> </data>

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.