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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:18:43+00:00 2026-05-16T20:18:43+00:00

i have a class like class CXmlData { String Data1=; String Data2=; List<String> lst=new

  • 0

i have a class like

class CXmlData
    {
        String Data1="";
        String Data2="";
        List<String> lst=new List<String>()
    }

and a Dictionary

Dictionary<String,CXmlData> dict=new Dictionary<String,CXmlData>();

The xml file is having the following structure

<Root>
    <ChildList>
        <Children>
            <Child Name="a1" val="A"/>
            <Child Name="a2" val="A"/>
            <Child Name="b1" val="B"/>
            <Child Name="c1" val="C"/>
            <Child Name="c2" val="C"/>
        </Childen>
        <Siblings_One>
              <Sibling Name="A" Xpos="0" Ypos=""/>
              <Sibling Name="B" Xpos="1" Ypos="1"/>
        </Sibling_One>
        <Siblings_Two>
              <Sibling Name="C" Xpos="0" Ypos="0"/>              
        </Sibling_Two>
    </ChildList>
</Root>

i need to read the data from the above xml file and to add to the dictionary

so the Resulting Dictionary will be like

    Key(String)          Value(Instance of CXmlData)

        "A"                   Data1="0"
                           Data2="2"
                              lst=new List<String>{"a1","a2"}

        "B"                   Data1="1" 
                              Data2="1"
                              lst=new List<String>{"b1"}

        "C"                   Data1="0"
                              Data2="2"
                              lst=new List<String>{"c1","c2"}

(if Xpos value is “0” then Data2(Ypos) value should be “2”)
Now I’m using like

1.Read Sibling_One child values

if Xpos value is “0” the take Ypos value as”2″

else keep the same

2.Read Sibling_Two child values

if Xpos value is “0” the take Ypos value as”2″

else keep the same

3.Read Children->Child values

Compare Sibling->Name attribute ==Child->Name

if matches then add the Child->Name attribute value to the list

i’m using Xml Namespace(System.Xml) and foreach loop for this, but its taking more time to complete the process

EDIT Sample Code

            XmlDocument XDoc = new XmlDocument();
            XDoc.Load(Application.StartupPath + "\\foo.xml");
            XmlElement XRoot = XDoc.DocumentElement;
            List<string> TempList = new List<string>();
            XmlNodeList XChildName = XDoc.SelectNodes("//ChildList/Sibling_One/Sibling");
            foreach (XmlNode ch in XChildName)
            {
                TempList .Add(ch.Attributes["Name"].Value);
                CXmlData P = new CXmlData();
                if (ch.Attributes["Xpos"].Value == "0")
                    P.Data2 = "2";
                else
                    P.Data2 = ch.Attributes["Ypos"].Value;
                P.Data1 = ch.Attributes["Xpos"].Value;
                dict.Add(ch.Attributes["NetName"].Value, P);

            }
            XChildName = XDoc.SelectNodes("//ChildList/Sibling_Two/Sibling");
            foreach (XmlNode ch in XChildName)
            {
                TempList .Add(ch.Attributes["Name"].Value);
                CXmlData P = new CXmlData();
                if (ch.Attributes["Xpos"].Value == "0")
                    P.Data2 = "2";
                else
                    P.Data2 = ch.Attributes["Ypos"].Value;
                P.Data1 = ch.Attributes["Xpos"].Value;
                dict.Add(ch.Attributes["Name"].Value, P);
            }

            foreach (string str in TempList )
            {
                List<String> lstChildValues = (from XmlNode xn in XDoc.SelectNodes("//ChildList/Children/Child")
                            where xn.Attributes["val"].Value == str
                            select xn.Attributes["Name"].Value).ToList();

                if (dict.Keys.Contains(str))
                {

                    CXmlData p = dict[str];
                    dict.Remove(str);
                    p.lst = lstChildValues;
                    dict.Add(str, p);
                }
            }

is there any way to do this using LINQ to Xml (System.xml.Linq)?

  • 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-16T20:18:44+00:00Added an answer on May 16, 2026 at 8:18 pm
     List<String>l_lstName = XDocument.Load("foo.xml")
                                   .Descendants("Sibling")
                                   .Select(Temp => Temp.Attribute("Name").Value).ToList();
    
    
            Dictionary<String, CXmlData> dict = new Dictionary<string, CXmlData>();
    
    
    
    
    
            dict = XDocument.Load("foo.xml")
                                   .Descendants("Sibling").ToDictionary(
                                   X => X.Attribute("Name").Value,
                                   X => new CXmlData
                                   {
                                       lst =XDocument.Load("foo.xml").Descendants("Children").Descendants("Child").Where(Temp=>Temp.Attribute("val").Value==X.Attribute("Name").Value).Select(Temp=>Temp.Attribute("Name").Value).ToList(),
                                       Data1 = X.Attribute("Xpos").Value == "0" ? "2" : X.Attribute("Ypos").Value,
                                       Data2 = X.Attribute("Xpos").Value
                                   }
                                   );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In jQuery 1.4+, you can pass a function to .replaceWith(),… May 16, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer Yes you can normally add new dialogs to visual studio… May 16, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer Which fields do you want to convert to string? If… May 16, 2026 at 9:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have class like this: public class object { [Key] int number; String mystring;
I want to have an class like this, public class Apple { public string
Let's say I have a class like this: public class Person { private String
i have class like this DrillDownAppAppDelegate.h PictureCell.h RootViewController.h SlideShowViewController.h DrillDownAppAppDelegate.m PictureCell.m RootViewController.m SlideShowViewController.m i
I have class like public class ProgressBars { public ProgressBars() { } private Int32
Guys if I have class like below: template<class T> class X { T** myData_;
I have a class like the following: public class DropDownControl<T, Key, Value> : BaseControl
I have a class like this: public class Stretcher : Panel { public static
My question is shown in this code I have class like that public class
I have a class like: class Spline int ChildrenCount; Spline GetChild (int index) 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.