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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:29:56+00:00 2026-05-12T15:29:56+00:00

How can query below document so it would give me value of id (the

  • 0

How can query below document so it would give me value of “id” (the one in the root after status) ?

this gives an error (Object reference not set to an instance of an object.)

            using (WebResponse response = request.GetResponse())
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string responseString = reader.ReadToEnd();
                XDocument document = XDocument.Parse(responseString, LoadOptions.None);
                return (from e in document.Root.Elements("status")
                        select e.Element("id").Element("name").Value).SingleOrDefault().ToString();
                return responseString;
            }
        }

XML

<?xml version="1.0" encoding="UTF-8"?>
<status>
  <created_at>Tue Sep 29 09:33:23 +0000 2009</created_at>
  <id>xxxxxxxxxxxxxx</id>
  <text>test</text>
  <source><a href="http://apiwiki.twitter.com/" rel="nofollow"&gt;API</a&gt;</source>
  <truncated>false</truncated>
  <in_reply_to_status_id></in_reply_to_status_id>
  <in_reply_to_user_id></in_reply_to_user_id>
  <favorited>false</favorited>
  <in_reply_to_screen_name></in_reply_to_screen_name>
  <user>
    <id>xxxx</id>
    <name>xxx</name>
    <screen_name>xxx</screen_name>
   </user>
</status>
  • 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-12T15:29:56+00:00Added an answer on May 12, 2026 at 3:29 pm

    Your root element is already ‘status’. Therefore the following code:

    return (from e in document.Root.Elements("status")
                            select e.Element("id").Element("name").Value).SingleOrDefault().ToString();
    

    needs to read:

    return document.Root.Element("id").Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using a query like below you can fetch rows in which the color of
Can anyone help or provide me with some suggestions for the below query. I
How can I optimize below SQL (simplified view of my complex query.) Ideally, I
I can't seem to make the code below work after an initial successful click.
below is my xml document and right now my query is: /description/*/text() , I
The script below works as far as i can tell: <script type=text/javascript language=javascript> $(document).ready(function()
I can query for the picture,location and privacy fields/connections of a users Facebook event
Is there a table i can query all of Oracle Reserved Words? Example, i
I am having trouble writing query so that I can query the content of
I am programming a server daemon from which users can query data in C.

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.