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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:07:07+00:00 2026-06-15T07:07:07+00:00

I am doing some practice code with the XmlTextReader. I have written some very

  • 0

I am doing some practice code with the XmlTextReader. I have written some very basic XML as shown here:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<task name="mixed_sprite_task_test">
    <sprite>
        <type>animatedSprite</type>
        <id>0</id>
        <name>animatedSprite</name>
        <fileName>iyezoz</fileName>
        <startingPositionX>200</startingPositionX>
        <startingPositionY>200</startingPositionY>
        <sheetSizeX>12</sheetSizeX>
        <sheetSizeY>35</sheetSizeY>
        <startingFrameX>0</startingFrameX>
        <startingFrameY>0</startingFrameY>
        <startingState>standing</startingState>
        <movementSpeed>15</movementSpeed>
        <frameDelay>0.055</frameDelay>
    </sprite>
    <sprite>
        <type>staticSprite</type>
        <id>0</id>
        <name>staticSprite</name>
        <fileName>Super_Mario_63</fileName>
        <startingPositionX>0</startingPositionX>
        <startingPositionY>0</startingPositionY>
    </sprite>
    <sprite>
        <type>simpleSprite</type>
        <id>0</id>
        <name>simpleSprite</name>
        <fileName>imgres</fileName>
        <startingPositionX>100</startingPositionX>
        <startingPositionY>100</startingPositionY>
        <movementSpeed>15</movementSpeed>
    </sprite>
</task>

This file shows that I have a task. In the task I have 3 sprites.
In my code I want to loop through each sprite and collect the information.

I can get the data from the first sprite with no issue. Is there a certain way to loop through an xml with attributes of the same name?

Thank-you!

  • 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-15T07:07:09+00:00Added an answer on June 15, 2026 at 7:07 am

    I prefer Linq2Xml.

    var xDoc = XDocument.Parse(xmlstring); //or XDocument.Load(filename);
    var sprites = xDoc.Descendants("sprite")
                    .Select(s=>s.Elements()
                                .ToDictionary(e=>e.Name.LocalName,e=>(string)e))
                    .ToList();
    

    You can use it as

    var type = sprites[0]["type"];
    

    or can take a safe action

    string delay;
    if (sprites[1].TryGetValue("frameDelay", out delay))
    {
        Console.WriteLine(delay);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing some practice for my O/SCJP exam. Consider the following code: public
im doing some practice sql problems one of the questions is: Prepare a shipping
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read
There has been some controversy regarding the practice of doing the following: a, input,
I have some code that I want to execute if an exception happens. But
I have some code for converting some timestamps stored as strings into datetime objects
new Android developer here. I'm doing a form that let's users set up some
i am doing some practice on the codeigniter to retrieve the data from database
I'm doing some programming practice right now by trying to sort a 2D array

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.