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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:04:59+00:00 2026-06-11T03:04:59+00:00

I have this XML which contains a list of entities: <?xml version=1.0 encoding=utf-8 ?>

  • 0

I have this XML which contains a list of entities:

<?xml version="1.0" encoding="utf-8" ?>
<Connections>
  <Connection>
    <ConnectionName>connName</ConnectionName>
    <InterfaceName>Account Lookup</InterfaceName>
    <RequestFolder>C:\Documents and Settings\user\Desktop\Requests</RequestFolder>
    <ResponseFolder>C:\Documents and Settings\user\Desktop\Responses</ResponseFolder>
  </Connection>
</Connections>

I’m trying to retrive one of them based on its name and build an object from it.

var results = (from i in this.Elements("Connection")
                           where i.Element("ConnectionName").ToString() == stubConnectionName
                           select new {
                               interfaceName = ((string)i.Element("InterfaceName").Value),
                               requestFolder = ((string)i.Element("RequestFolder").Value),
                               responseFolder = ((string)i.Element("ResponseFolder").Value),
                           }).Single();

return new StubConnection(stubConnectionName, results.interfaceName, results.requestFolder, results.responseFolder);

The problem is that results comes back empty. What is wrong with my query?

  • 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-11T03:05:00+00:00Added an answer on June 11, 2026 at 3:05 am
    where i.Element("ConnectionName").ToString() == stubConnectionName
    

    has to be:

    where i.Element("ConnectionName").Value == stubConnectionName
    

    because XElement.ToString returns <ConnectionName>connName</ConnectionName> including the XML tags, while XElement.Value only returns the enclosed connection name without the tags.

    By the way, you are unnecessarily casting all the values (which are already of type string) to string. You can simplify that:

    var results = (from i in this.Elements("Connection")
                   where i.Element("ConnectionName").Value == stubConnectionName
                   select new
                   {
                       interfaceName = i.Element("InterfaceName").Value,
                       requestFolder = i.Element("RequestFolder").Value,
                       responseFolder = i.Element("ResponseFolder").Value,
                   }).Single();
    

    You could even go one step further and directly select and return your result, without using an anonymous type in between:

    return (from i in this.Elements("Connection")
            where i.Element("ConnectionName").Value == stubConnectionName
            select new StubConnection(stubConnectionName,
                                      i.Element("InterfaceName").Value,
                                      i.Element("RequestFolder").Value,
                                      i.Element("ResponseFolder").Value)).Single();
    

    Please also understand the differences of

    XElement.Value vs (string)XElement

    Be careful when calling the Value property directly, as it will throw an Exception if the element contains no value. Cast the element (not the Value, but the XElement directly) to string if you are not sure whether it will contain a value. If it doesn’t, null will be returned; otherwise, the result is the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file frequencies.xml which contains lines with this form: <?xml version=1.0?> <!DOCTYPE
I have some XML which contains records and sub records, like this: <data> <record
I have a XML column which contains XML like this: <Set> <Element> <ID> 1
I have the following layout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical android:background=#EAEAEA>
I want to read XML like this. <?xml version=1.0 encoding=utf-8 ?> <parent> <path> <pathPoints>
I have an XML string which contains Dates formatted dd/MM/yyyy hh:mm:ss. I'm loading this
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
I have this xml from which I am trying to grab the value in
I have this xml file which has text init. i.e Hi my name is
I have this XML of products which I'm trying to validate. (i keep it

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.