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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:33:35+00:00 2026-06-06T17:33:35+00:00

I’m trying to find the inner text value of an element using LINQ-to-XML (an

  • 0

I’m trying to find the inner text value of an element using LINQ-to-XML (an XElement object). I make my service call and get an XML response back that I’ve successfully loaded into an XElement object. I want to extract the inner text of one of the elements – however, every time I try to do this, I get a null result.

I feel like I’m missing something super-simple, but I’m fairly new to LINQ-to-XML. Any help is appreciated.

I’m trying to get the inner text value of the StatusInfo/Status element. Here’s my XML document that’s returned:

<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">My Response</title>
  <id>tag:foo.com,2012:/bar/06468dfc-32f7-4650-b765-608f2b852f22</id>
  <author>
    <name>My Web Services</name>
  </author>
  <link rel="self" type="application/atom+xml" href="http://myServer/service.svc/myPath" />
  <generator uri="http://myServer" version="1">My Web Services</generator>
  <entry>
    <id>tag:foo.com,2012:/my-web-services</id>
    <title type="text" />
    <updated>2012-06-27T14:22:42Z</updated>
    <category term="tag:foo.com,2008/my/schemas#system" scheme="tag:foo.com,2008/my/schemas#type" />
    <content type="application/vnd.my.webservices+xml">
      <StatusInfo xmlns="tag:foo.com,2008:/my/data">
        <Status>Available</Status>  <!-- I want the inner text -->
      </StatusInfo>
    </content>
  </entry>
</feed>

Here’s a snippet of code that I’m using to extract the value (which doesn’t work):

    XElement root = XElement.Load(responseReader);
    XNamespace tag = "tag:foo.com,2008:/my/data";
    var status = (from s in root.Elements(tag + "Status")
                 select s).FirstOrDefault();

My status variable is always null. I’ve tried several variations on this, but to no avail. The part that’s confusing me is the namespace — tag and 2008 are defined. I don’t know if I’m handling this correctly or if there’s a better way to deal with this.

Also, I don’t have control over the XML schema or the structure of the XML. The service I’m using is out of my control.

Thanks for any help!

  • 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-06T17:33:36+00:00Added an answer on June 6, 2026 at 5:33 pm

    Try Descendants() instead of Elements():

    XElement x = XElement.Load(responseReader);
    XNamespace ns = "tag:foo.com,2008:/my/data";
    var status = x.Descendants(ns + "Status").FirstOrDefault().Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to select an H1 element which is the second-child in its group
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.