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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:44:39+00:00 2026-06-04T16:44:39+00:00

I’m trying to put sub-child values from XML into a dictionary collection using LINQ.

  • 0

I’m trying to put sub-child values from XML into a dictionary collection using LINQ. I’ve done this with lists and custom collections which follow the same structure as the XML but am unable to search for specific values. If I know parentName, childName, and subChildName I want to be able to find subChildProperty1.value and subChildProperty2.value without iterating through the entire collection and each of the subsequent sub-collections, as I have to do with lists. This may not be the best implementation, and am open to suggestions, but still would like to figure out how to make this work. This would then allow me to have a dictionary item be:

key = "parentNameValue1.childNameValue1.subchildNameValue1.subChildProperty1"
value = 0

and I could just concatenate strings to form a specific key and search on that key to return a value.

XML:

<root>
    <parent>
        <parentName>parentNameValue1</parentName>
        <child>
            <childName>childNameValue1</childName>
            <subchild>
                <subchildName>subchildNameValue1</subchildName>
                <subChildProperty1>0</subChildProperty1>
                <subChildProperty2>5</subChildProperty2>
            </subchild>
            <subchild>
                <subchildName>subchildNameValue2</subchildName>
                <subChildProperty1>0</subChildProperty1>
                <subChildProperty2>10</subChildProperty2>
            </subchild>
        </child>
    </parent>
<root>

This question is somewhat similar to this question here but I could not get the code working in VB for my application.

I am new to SO (and VB) so I apologize if my etiquette is incorrect.

  • 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-04T16:44:40+00:00Added an answer on June 4, 2026 at 4:44 pm

    With VB.NET’s great XML support, this is quite easy to do:

    Imports System.Xml.Linq
    
    ...
    
    Sub Main()
        Dim xml = _
            <root>
                <parent>
                    <parentName>parentNameValue1</parentName>
                    <child>
                        <childName>childNameValue1</childName>
                        <subchild>
                            <subchildName>subchildNameValue1</subchildName>
                            <subChildProperty1>0</subChildProperty1>
                            <subChildProperty2>5</subChildProperty2>
                        </subchild>
                        <subchild>
                            <subchildName>subchildNameValue2</subchildName>
                            <subChildProperty1>0</subChildProperty1>
                            <subChildProperty2>10</subChildProperty2>
                        </subchild>
                    </child>
                </parent>
            </root>
    
        ' Alternatively, load XML from a file
        ' Dim xml = XDocument.Load(fileName)
    
        Dim dict As New Dictionary(Of String, Integer)
    
        ' Extract the properties
        For Each parent In xml.<parent>
            Dim parentName = parent.<parentName>.Value
            For Each child In parent.<child>
                Dim childName = child.<childName>.Value
                For Each subchild In child.<subchild>
                    Dim subchildName = subchild.<subchildName>.Value
                    For Each prop In subchild.Elements.Where(Function(e) e.Name <> "subchildName")
                        dict.Add(String.Format("{0}.{1}.{2}.{3}", parentName, childName, subchildName, prop.Name), _
                                 Integer.Parse(prop.Value))
                    Next
                Next
            Next
        Next
    
        ' Print the values, to show that we've done a good job
        For Each kv In dict
            Console.WriteLine("{0}: {1}", kv.Key, kv.Value)
        Next
        Console.ReadLine()
    End Sub
    

    (Clearly, the code assumes Option Strict On and Option Infer On.)

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I am trying to loop through a bunch of documents I have to put

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.