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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:20:48+00:00 2026-06-11T05:20:48+00:00

Trying to use Linq to XML for the first time and having some problems.

  • 0

Trying to use Linq to XML for the first time and having some problems. I have this XML file that needs to be read and used for various tasks. The file contains a list of entities called ‘interfaces’. To start with I want to display a list of names of these interfaces.

Here is the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<InterfaceList>
  <Interface>
    <InterfaceName>Account Lookup</InterfaceName>
    <RequestXSD>ALREQ.xsd</RequestXSD>
    <ResponseXSD>ALRES.xsd</ResponseXSD>
  </Interface>
  <Interface>
    <InterfaceName>Balance Inquiry</InterfaceName>
    <RequestXSD>BIREQ.xsd</RequestXSD>
    <ResponseXSD>BIRES.xsd</ResponseXSD>
  </Interface>
</InterfaceList>

Here is the query code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Stub {
    public class InterfaceList : XElement {

        public void GetInterfaceNameList() {
            var v = from interface in this.Elements("Interface")
                select interface.Element("InterfaceName").Value;
        }
    }
}

The idea is to load InterfaceList from the file, and then to use it to query any I may need.
The problem is that I’m getting error message for everything in the query. here are a few of them:

  • Error 14 The name ‘from’ does not exist in the current context
  • Error 15 The type or namespace name ‘select’ could not be found (are
    you missing a using directive or an assembly reference?)
    Error
  • Error 16 ‘System.Xml.Linq.XElement.Value’ is a ‘property’ but is used
    like a ‘type’

What’s wrong here?

  • 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-11T05:20:50+00:00Added an answer on June 11, 2026 at 5:20 am

    If you want to call your variable ‘interface’ (which is a reserved word) you will need to escape it, like this:

    var v = from @interface in this.Elements("Interface")
            select @interface.Element("InterfaceName").Value;
    

    Probably better to just rename it though….

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

Sidebar

Related Questions

I am trying to read a value from an XML file using LINQ. This
Possible Duplicate: Use LINQ to read all nodes from XML I am trying to
I am trying to use Linq to XML to save & retrieve some HTML
Hi I’m trying to use a DataGridView for the first time and with LINQ.
Ok, so I have an XML file that pretty much looks like this: <Templates>
I am trying to use LINQ to return a list of tasks that are
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I'm trying to run a T4 template that opens a XML file and uses
I am trying to use LINQ to XML in an with the XDocument object.
I am querying an HTML file with LINQ-to-XML. It looks something like this: <html>

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.