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

  • Home
  • SEARCH
  • 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 8586929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:26:18+00:00 2026-06-11T22:26:18+00:00

Given the following XML section from a large xml file: <item id=C3DD6846593 > <name

  • 0

Given the following XML section from a large xml file:

<item id="C3DD6846593" >
    <name xml:lang="fr">Atlantique</name>
    <name xml:lang="en">Atlantic </name>
</item>

I’m trying to load an object in Linq based on the attribute of a node. Here is what I tried to do in the code.

public class MyList
    {
        public string ID {get;set;}

        public string EnName {get;set;}

        public string FrName {get;set;}

        public MyList() { }
    }

…… later in code

  AgencyList = (from x in rawSrc.Descendants("item")                          
                                select new MyList{
                                    ID = x.Attribute("id").Value
                                    EnName = x.XPathSelectElement("\\name[@lang='en']").Value,
                                    FrName =x.XPathSelectElement("\\name[@lang='fr']").Value
                                }).ToList();

I get ” ‘\name[@lang=’en’]’ has an invalid token.” as the error. Is there another way to approach this?

  • 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-11T22:26:19+00:00Added an answer on June 11, 2026 at 10:26 pm

    You need to use a normal slash instead of a backslash. Additionally, you need to add the namespace of the attribute and pass in an instance of IXmlNamespaceResolver:

    EnName = x.XPathSelectElement("//name[@xml:lang='en']", ns).Value,
    FrName = x.XPathSelectElement("//name[@xml:lang='fr']", ns).Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following: >>> from lxml import etree >>> contents=open('file.xml').read() >>> node=etree.fromstring(contents) How would
Given the following XML (in an SQL column field called 'xfield'): <data> <section> <item
Given the following XML file: <users> <user name=admin password=foobar roles=Admin,Guest /> <user name=guest password=foobar
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <doc> <head> <title>Introduction</title> <section>section</section> <channel>testing/test</channel> </head>
Given the following XML: <Contact> <ContactID>41111-f15a-4fa1-b643-47877608f557</ContactID> <ContactStatus>ACTIVE</ContactStatus> <Name>ABC Ltd</Name> <EmailAddress>xxx@xxx.co</EmailAddress> <SkypeUserName>xxxdemo</SkypeUserName> <Addresses> <Address> <AddressType>STREET</AddressType>
Given the following xml: <!-- file.xml --> <video> <original_spoken_locale>en-US</original_spoken_locale> <another_tag>somevalue</another_tag> </video> What would be
Given the following repository URL from my pom.xml how can I determine what the
I have the following XML: <assessment> <section> <item> <attributes> <variables> <variable> <variable_name value=MORTIMER/> </variable>
Given the following XML: <root> <StepFusionSet name=SF1> <StepFusionSet name=SF2> </StepFusionSet> </StepFusionSet> <StepFusionSet name=SF10> </StepFusionSet>
Given the following partial XML document: <section> <entry typeCode=DRIV> <act classCode=AT moodCode=DEF> <statusCode code=completed/>

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.