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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:26:21+00:00 2026-06-13T03:26:21+00:00

I have an existing List<MyObject> containing 15 MyObject(s). I want to read an XML

  • 0

I have an existing List<MyObject> containing 15 MyObject(s). I want to read an XML document and map the XML document to this data.

The MyObject class has 3 public properties;

+id :int
+value1 :float
+value2 :float

The XML document has this structure;

  <root>

    <objects>
         <object id="1">
             <value1>S</value1>
             <value2>B</value2>
         </object>
         <object id="2">
             <value1>A</value1>
             <value2>J</value2>
         </object>
     </objects>
   </root>

Although the original List<MyObject> has 15 items, the incoming XML document only has 2 items, I need to maps the XML objects by id and change the List values.

so the data for XML document

object id=1, value1 = s, value2= b
object id=2, value1 = a, value2= j

and the data for the List<MyObject> items are

object id=1 value1= a, value2 = b
object id=2 value1= c, value2 = d
object id=3 value1= k, value2 = z
object id=4 value1= y, value2 = e

I need to read the XML document and merge it with the existing List<MyObject>
the result of the list should look like;

object id=1 value1= s, value2 = b
object id=2 value1= a, value2 = j
object id=3 value1= k, value2 = z
object id=4 value1= y, value2 = e
  • 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-13T03:26:22+00:00Added an answer on June 13, 2026 at 3:26 am

    Try this

    using System.Xml;
    
    ...
    
    XmlDocument doc = new XmlDocument();
    doc.Load("filename.xml"); //or doc.LoadXml(xmlString);
    XmlNodeList objects = doc.GetElementsByTagName("object"); //get list of objects from XML
    
    List<object> myObjects = new List<object> { new object()}; //replace this with your List<object>
    
    for (int i = 0; i < myObjects.Count; i++)
    {
        foreach (XmlNode o in objects)
        {
            if (o.Attributes["id"].Value == myObjects[i].id.ToString())
            {
                myObjects[i].Value1 = o.ChildNodes[0].InnerText;
                myObjects[i].Value2 = o.ChildNodes[1].InnerText;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# class called SmallClass. I have an existing list myList containing
I have generalized the existing Data.List.partition implementation partition :: (a -> Bool) -> [a]
I have an existing list instance, which in live code has references throughout. When
I have an existing controller action as below. Public Function List(ByVal UserID As Integer,
I have existing Linux shared object file (shared library) which has been stripped. I
I have existing java code and need to create Design Document based on that.
I have existing code with their own makefiles which I want to load into
I have an existing web service and I want it to expose 2 MEX
I have a list of tuples with three values in tuples I want to
I have created a Custom List Template and wrote the Schema.xml,feature to deploy it,Installed

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.