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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:09:53+00:00 2026-05-28T15:09:53+00:00

I’m new to LINQ to XML and I have been looking at tutorials but

  • 0

I’m new to LINQ to XML and I have been looking at tutorials but I’ve not found one that has sufficient depth to get me past my block. In my case I hit a vendor of ours for information on a given address. There is the possibility that the address will not be an exact match so they send me back an XML file that has possible addresses.

Here is a given chunk of XML for a multiple list of addresses coming back from an address query:

    <POSSIBLE-ADDRESSES>
              <POS-ADDR>
                <BUILDING>
                  <Street>1905 W HENDERSON RD                                      </Street>
                  <City>COLUMBUS                      </City>
                  <RiskID>123456</RiskID>
                </BUILDING>
                <OCCUPANTS>
                  <OCCUP>
                    <ID>010</ID>
                    <Desc>MC DONALD'S RESTAURANT (1S)        </Desc>
                  </OCCUP>
                  <OCCUP>
                    <ID>015</ID>
                    <Desc>MC DONALD'S RESTAURANT             </Desc>
                  </OCCUP>
                </OCCUPANTS>
              </POS-ADDR>
              <POS-ADDR>
                <BUILDING>
                  <Street>1821 HENDERSON RD                                        </Street>
                  <City>UPPER ARLINGTON               </City>
                  <RiskID>1234567</RiskID>
                </BUILDING>
                <OCCUPANTS>
                  <OCCUP>
                    <ID>010</ID>
                    <Desc>ARLINGTON SQUARE SHOPPING CTR (1S) </Desc>
                  </OCCUP>
                  <OCCUP>
                    <ID>015</ID>
                    <Desc>1821 SWAN DRY CLNG                 </Desc>
                  </OCCUP>
                  <OCCUP>
                    <ID>020</ID>
                    <Desc>4681 ALEX'S BISTRO ON REED/REST    </Desc>
                  </OCCUP>
                  <OCCUP>
                    <ID>025</ID>
                    <Desc>4687-93 BLUMEN GARTEN              </Desc>
                  </OCCUP>
                  <OCCUP>
                    <ID>030</ID>
                    <Desc>4697 BLIMPIE/SANDWICH SHOP         </Desc>
                  </OCCUP>
                </OCCUPANTS>
              </POS-ADDR>
            </POSSIBLE-ADDRESSES>

Now what I do is pull all the buildings (mind you there can be many more than this) with the following and then bind that to a list box – no biggie:

    var qBuildings = from LOP in loaded.Descendants("BUILDING")
    select new
    {
      BuildingName = LOP.Element("Street").Value,
      RiskId = LOP.Element("RiskID").Value
    };

This gives me all the buildings that I need along with their risk ID’s.

Now the kicker is how to pull the “occupants” when the user selects a given building based on the risk ID say the first RiskID of “123456”. So if the user selects this building it will go out and grab each occupant hydrating an occupant class and add that class to a list of occupants which I will then bind to another list box.

Everything I’ve tried so far has had bad results at just trying to get the occupants. I know it must be a matter of navigation but I can’t seem to build the query in a way that returns anything useful. Each risk ID is unique and each building can have none or many occupants. So I’m lost at how to pull the occupants.

Any help would be appreciated.

  • 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-28T15:09:54+00:00Added an answer on May 28, 2026 at 3:09 pm

    It seems to me you want to select occupants from a pos-addr, whose building has a specific riskId. In LINQ-to-XML, that could look like this:

    var posAddr =
        (from pos in possibleAddresses.Elements("POS-ADDR")
         where (int)pos.Element("BUILDING").Element("RiskID") == riskIdToLookFor
         select pos)
        .Single();
    
    var occupants =
        from o in posAddr.Element("OCCUPANTS").Elements("OCCUP")
        select new
        {
            Description = (string)o.Element("DESC")
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.