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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:33:57+00:00 2026-05-18T21:33:57+00:00

I have an .asmx webservice that returns some XML. A sample bit of XML

  • 0

I have an .asmx webservice that returns some XML. A sample bit of XML looks like:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">http://www.mydomain.com/sample.txt</string>

I’m new to LINQ but would like to get familiar with it. I need to get the value of inside the string element. But I’m not sure how to do it with LINQ. Currently, I’m trying:

string text = GetXmlText();
XDocument xml = XDocument.Parse(text);
string url = xml.Descendants("string").SingleOrDefault().Value;

This code throws an exception. But I’m not sure what I’m doing wrong. How do I get the response value with LINQ?

Thanks!

  • 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-18T21:33:57+00:00Added an answer on May 18, 2026 at 9:33 pm

    For this particular usage, all you need is this, because the XML you provided contains only a root node and you want its value.

    string url = xml.Root.Value;
    

    If the XML is indeed more complicated, please elaborate. But take a look at the xmlns attribute in the string element. To handle situations when you would like to refer to a particular element or descendant directly, you need to utilize an XNamespace object.

    XNamespace ns = "http://tempuri.org/";
    string url = (string)xml.Descendants(ns + "string").FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net web service that takes some xml data. From within the
I have a webservice that calls a method that returns a generic list of
I have a Page that expects a POST Request and returns some JSON. Essentially
Why is that Web Service files (.asmx) have their code-behind placed in app_code folder
I have a web service (ASMX) and in it, a web method that does
I have a webservice (asmx file) in a directory requiring form authentication When I
I have a script that appends some rows to a table. One of the
Say I have an ASMX web service, MyService. The service has a method, MyMethod.
I have a web service (WCF or ASMX doesn't matter)... I have made a
I have an .asmx in a folder in my application and I keep getting

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.