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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:36:05+00:00 2026-06-08T15:36:05+00:00

Possible Duplicate: Parsing XML String in C# How to process the below XML file

  • 0

Possible Duplicate:
Parsing XML String in C#

How to process the below XML file and store the element value in an array

  <UserID>
  <Total>2</Total>
  <X1>2</X1>
  <Y1>4</Y1>
  <Attached1>2,3,4</Attached1>
  <X2>7</X2>
  <Y2>8</Y2>
  <Attached2>4,5,6</Attached2>
  </UserID>

Here I need to parse the elements X1 and X2 and store them in the same array.

Similarly I need to parse the Elements for Y1, Y2 and Attached1, Attached2 and store them in the same array.

This file may grow or shrink dynamically.

We can have X1, X2 up to X100 elements or X1, X2, up to X10 elements.

I do not want it to be restricted to few elements.

Here Total element indicates that there can be two X elements like X1 and X2

If the value of total is 5 then there can be 5 X elements like X1, X2, X3, X4 and X5.

I need to parse and store the values dynamically.

Any help?

  • 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-08T15:36:08+00:00Added an answer on June 8, 2026 at 3:36 pm

    I just have to say, the design of the document is bad. You shouldn’t name your elements to indicate their position. Just give them a single common name and add as many as you need.

    With that said, in your case you can generate the names (assuming they will always be sequential).

    var xmlStr = @"<UserID>
      <Total>2</Total>
      <X1>2</X1>
      <Y1>4</Y1>
      <Attached1>2,3,4</Attached1>
      <X2>7</X2>
      <Y2>8</Y2>
      <Attached2>4,5,6</Attached2>
    </UserID>
    ";
    var doc = XDocument.Parse(xmlStr);
    var users =
        from user in doc.Descendants("UserID")
        let total = (int)user.Element("Total")
        select new
        {
            X = Enumerable.Range(1, total)
                          .Select(i => (int)user.Element("X" + i))
                          .ToArray(),
            Y = Enumerable.Range(1, total)
                          .Select(i => (int)user.Element("Y" + i))
                          .ToArray(),
            Attached = Enumerable.Range(1, total)
                                 .Select(i => (string)user.Element("Attached" + i))
                                 .ToArray(),
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Parsing XML in Cocoa iPhone - Can we parse .plist(xml) file using
Possible Duplicate: Parsing XML data to NSMutableArray iOS - iPhone <ForecastResult> <Forecast> <Date>2012-06-27T00:00:00</Date> <WeatherID>4</WeatherID>
Possible Duplicate: Workarounds for JavaScript parseInt octal bug Parsing a string using parseInt method
Possible Duplicate: When is it OK to use an XML file to save information?
Possible Duplicate: Parsing text in C Say I have written to a text file
Possible Duplicate: Workarounds for JavaScript parseInt octal bug I'm parsing a string to check
Possible Duplicate: Comparison of XML parsing APIs on the Java SE platform I am
Possible Duplicate: Parsing Dates and Times from Strings using python I'm reading a string
Possible Duplicate: passing an empty array as default value of optional parameter in c#
Possible Duplicate: Parsing blank XML tags with LXML and Python Given the following XML

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.