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

The Archive Base Latest Questions

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

I have a program where the variable week is made up of object array[7]

  • 0

I have a program where the variable week is made up of object array[7] days and days is made up of object array[9] hours. Each hours object has 3 data members. I want to assign each member of a particular day and hour a specific value from an xml file:

   <parent> 
        <day>wednesday
            <hour>18.00 
                <value1>5</value1>
                <value2>10</value2>
                <value3>15</value3>
            </hour>
        </day>
        <day>thursday
            <hour>18.00 
                <value1>2</value1>
                <value2>3</value2>
                <value3>9</value3>
            </hour> 
        </day>
   </parent>

        day[wedensday].hour[18.00].member1 = xml.day[wednesday].hour[18.00].value1
        day[wedensday].hour[18.00].member1 = xml.day[wednesday].hour[18.00].value2
        day[wedensday].hour[18.00].member1 = xml.day[wednesday].hour[18.00].value3

I am new to working with xml and have come up with the following pseudo code but am having difficultly implementing it:

    member[i] = value[i] where day[i].name == xml.day && day[i].hour[i] == xml.hour

If anyone could guide me or direct me to a resource that would help with this problem it would be much appreciated, thanks 🙂

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

    You can parse your xml with Linq to xml:

    XDocument xdoc = XDocument.Load(path_to_xml_file);
    var week = new
    {
        Days = xdoc.Descendants("day")
                    .Select(day => new {
                        Name = ((XText)day.FirstNode).Value.Trim(),
                        Hours = day.Descendants("hour")
                                    .Select(hour => new {
                                        Time = ((XText)hour.FirstNode).Value.Trim(),
                                        Values = hour.Elements()
                                                    .Select(node => (int)node)
                                                    .ToList()
                                    }).ToList()
                    }).ToList()
    };
    

    week will be strongly-typed anonymous object. Usage:

    var daysCount = week.Days.Count; // 2 
    var secondDayName = week.Days[1].Name; // thursday
    var hoursInSecondDay = week.Days[1].Hours.Count; // 1
    var timeOfFirstHour = week.Days[1].Hours[0].Time; // 18:00
    var value3 = week.Days[1].Hours[0].Values[2]; // 9
    

    Explanation:

    xdoc.Descendants("day") returns all <day> nodes. But we don’t need xml nodes, so we do a projection, by selecting anonymous object, which will represent day. This object has two properties – Name and Hours. Name we get from first node of <day> element, which is text node (‘wednesday’ for first day). Hours we get by selecting <hour> elements of <day> and also making projection to anonymous object representing hour. Etc.


    If you will move day name and hour value to attributes like this:

    <parent>
      <day name="wednesday">  
        <hour time="18.00">    
          <value1>5</value1>
          <value2>10</value2>
          <value3>15</value3>
        </hour>
      </day>
    </parent>
    

    Then parsing will look like:

    XDocument xdoc = XDocument.Load(path_to_xml_file);
    var week = new
    {
        Days = xdoc.Descendants("day")
                    .Select(day => new {
                        Name = (string)day.Attribute("name"),
                        Hours = day.Descendants("hour")
                                    .Select(hour => new {
                                        Time = (string)hour.Attribute("time"),
                                        Values = hour.Elements()
                                                    .Select(node => (int)node)
                                                    .ToList()
                                    }).ToList()
                    }).ToList()
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that generates a variable amount of data that it has
I have program that has a variable that should never change. However, somehow, it
I have a program that defines a variable int data The program uses scanf(%d,&data)
Suppose I have a program that initializes a global variable for use by threads,
I have one WORD variable in my program. WORD hour; But when I compare
In following program . I have one doubt. I have declared one global variable
Basically, I want to have my program retrieve various variables from the hard drive
My program have two tabs, I set init variable in viewDidLoad. ( int A
I have one program which takes a set of statements into a variable, and
I have the following program that loops through all properties of my variable: class

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.