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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:58:47+00:00 2026-05-27T03:58:47+00:00

An example XML file is this: <?xml version=1.0 encoding=UTF-8?> <game> <name>bomber</name> <behaviors-used> <behavior id=Bullet

  • 0

An example XML file is this:

<?xml version="1.0" encoding="UTF-8"?>
<game>
    <name>bomber</name>
    <behaviors-used>
        <behavior id="Bullet" version="1">Bullet</behavior>
        <behavior id="Fade" version="1">Fade</behavior>
        <behavior id="Flash" version="1">Flash</behavior>
        <behavior id="Sin" version="1">Sine</behavior>
        <behavior id="scrollto" version="1">Scroll To</behavior>
    </behaviors-used>
</game>

I have the query:

var data = (from item in loaded.Descendants("game")
            select new
            {
                name = item.Element("name").Value,
                behaviorlist = item.Element("behaviors-used").Value
            }).Single();

Which seems to work fine. However, I need to now retrieve all the <behavior> elements in the behaviorlist. I can’t seem to do it like this:

var bq = (from c in data.behaviorlist select new { behaviour = c.Element("behaviour")});

(Throws invalid syntax errors).

How do I retrive all the behaviours and not only access their text but also the properties id and version?

  • 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-27T03:58:47+00:00Added an answer on May 27, 2026 at 3:58 am

    Your behaviorlist is not really a list right now – you want the elements not the combined text, so instead of using the Value property of the parent node, you should retrieve the Elements with name “behavior”:

    var data = (from item in loaded.Descendants("game")
                select new
                {
                    name = item.Element("name").Value,
                    behaviorlist = item.Element("behaviors-used").Elements("behavior")
                }).Single();
    

    From the resulting list you can then easily retrieve the properties:

    var bq = (from c in data.behaviorlist select new 
    { 
        id = c.Attribute("id").Value,
        version = c.Attribute("version").Value,
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file formatted like this: <?xml version=1.0 encoding=utf-8?> <Snippets> <Snippet name=abc>
Example XML using element nodes: <?xml version=1.0 encoding=utf-8?> <users> <user> <name>David Smith</name> <phone>0441 234443</phone>
Here's an example of an XML file created in InfoPath: <?xml version=1.0 encoding=UTF-8?> <?mso-infoPathSolution
I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
The top of my web.xml file looks like this: <?xml version=1.0 encoding=UTF-8?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee
I have the following (as an example) XML file and XSD. <?xml version=1.0 encoding=utf-8
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
For example <?xml version=1.0 encoding=UTF-8?> <!--just example, the actual element structure is rather complex
I have an XSD of this form: <?xml version=1.0 encoding=UTF-8?> <schema xmlns=http://www.w3.org/2001/XMLSchema targetNamespace=http://www.example.org/example xmlns:tns=http://www.example.org/example
I'd like to get all the element name from a xml file, for example

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.