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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:45:01+00:00 2026-05-16T18:45:01+00:00

I have a xml in the below format and need to get the id

  • 0

I have a xml in the below format and need to get the id and name of all the SubEntity when I pass the ParentEntityId. This needs to be done in silverlight.

<Treeview>
    <ParentEntity ParentEntityId="1" ParentEntityName="P1">
        <Facility FacilityId="F1" FacilityName="F1">
            <Category CategoryId="C1" CategoryName="C1"/>             
            <Category CategoryId="C2" CategoryName="C2" >
                <Activity ActivityId="A1" ActivityName="A1" /> 
            </Category>
        </Facility>
        <Facility FacilityId="F2" FacilityName="F2">
            <Category CategoryId="C1" CategoryName="C1">
                <Activity ActivityId="A2" ActivityName="A2" /> 
                <Activity ActivityId="A3" ActivityName="A3" />   
            </Category>
        </Facility>
        <SubEntity SubEntityId="S1" SubEntityName="S1">
            <SubEntity SubEntityId="S2" SubEntityName="S2"/> 
        </SubEntity>
        <SubEntity SubEntityId="S3" SubEntityName="S3">
            <SubEntity SubEntityId="S4" SubEntityName="S4">
                <Facility FacilityId="F3" FacilityName="F3">
                    <Category CategoryId="C1" CategoryName="C1 >
                        <Activity ActivityId="A1" ActivityName="A1" />   
                    </Category>
                </Facility>
            </SubEntity>
            <SubEntity SubEntityId="S5" SubEntityName="S5">
                <Facility FacilityId="F5" FacilityName="F5">
                    <Category CategoryId="C1" CategoryName="C1" />
                    <Category CategoryId="C2" CategoryName="C2"/>                
                </Facility>
            </SubEntity>
            <SubEntity SubEntityId="S6" SubEntityName="S6" />
        </SubEntity>
    </ParentEntity>
    <ParentEntity ParentEntityId="2" ParentEntityName="P2">
        <Facility FacilityId="F1" FacilityName="F1">
            <Category CategoryId="C1" CategoryName="C1"/>                   
        </Facility>
        <SubEntity SubEntityId="S7" SubEntityName="S7" />
    </ParentEntity>
</Treeview>

Assuming I pass my parentEntityId = 1, I need the output S1,S2,S3,S4,S5,S6.

Thanks in advance,
Sunitha

  • 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-16T18:45:01+00:00Added an answer on May 16, 2026 at 6:45 pm

    Using LINQ to XML

      foreach(XElement subEntity in doc.Root.Elements("ParentEntity")
           .First(elem => elem.Attribute("ParentEntityID").Value == "1")
           .Descendents("SubEntity") )
      {
         // Do stuff with each SubEntity e.g.:-
         string name = subEntity.Attribute("SubEntityName");
      }
    

    An alternative if you are using Silverlight 4 would be to use XPath instead. You would need to add the System.Xml.XPath.dll to your references. In that case the above loop becomes:-

      foreach(XElement subEntity in doc.Root
          .XPathSelectElements("ParentEntity[ParentEntityId='1']//SubEntity" )
      {
         // Do stuff with each SubEntity e.g.:-
         string name = subEntity.Attribute("SubEntityName");
      }
    

    BTW, You don’t in your real XML prefix all your attributes names with the name of the element they placed in do you? E.g., Why “SubEntityName” and not simply “Name”?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I have these xml files that have date ranges on them. Heres
I have written a program that reads in a File object (really an XML
I am using XStream to serialize my Objects to XML format. The formatted xml
I have a hibernate project, which uses JPA. my persistence.xml contents is as follows:
I have this script that I'd like to in addition save as a xls
i have a xml file and i am parsing it with DOM. ` <media:group>
I'm not the first to have these issues, and will list some reference posts
I have a requirement to geocode data using Google's geocoding service. Google's geocoding services
I have to call a Web service that is extremely demanding (unstandard) regarding the

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.