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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:11:19+00:00 2026-06-03T21:11:19+00:00

I have some XML documents: events.xml: <?xml version=1.0 encoding=UTF-8?> <events> <event> <id>9</id> <region>3</region> <region>12</region>

  • 0

I have some XML documents:

events.xml:

<?xml version="1.0" encoding="UTF-8"?>
<events>
  <event>
    <id>9</id> 
    <region>3</region> 
    <region>12</region> 
    <region>29</region> 
  </event>
  <event> 
    <id>7</id> 
    <region>1</region>
    <region>12345</region>
  </event>
  <event> 
    <id>3</id> 
    <region>12</region>
    <region>39</region> 
    <region>56</region> 
  </event>
  <event> 
    <id>8</id> 
    <region>8</region> 
    <region>123</region> 
    <region>456</region>
  </event>
  <event> 
    <id>4</id> 
    <region>999</region> 
    <region>888</region> 
    <region>777</region> 
  </event>
</events>

exposure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<companies>
  <company> 
    <id>6</id>
    <region>3</region>
    <region>9</region> 
    <region>8</region>
    <region>11111</region> 
    <region>12</region> 
  </company>
  <company> 
    <id>4</id> 
    <region>3</region> 
    <region>6</region> 
    <region>7</region> 
    <region>12345</region> 
  </company>
  <company> 
    <id>9</id> 
    <region>1</region> 
    <region>2</region> 
    <region>3</region> 
  </company>
</companies>

I need to write a program to process the two files:

For each event in the event file the program should write out the
event number followed by the set of companies it affects in the
exposure file. The list of companies should be written out in
ascending company number.

Given the sample files, the output should be something like this:

 9 4 6 9

 8 6

 7 4 9

 3 6
  • 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-03T21:11:20+00:00Added an answer on June 3, 2026 at 9:11 pm

    Have a little bit of LINQ in your life.

    var eventsDoc = XDocument.Load(@"events.xml");
    var exposureDoc = XDocument.Load(@"exposure.xml");
    
    var companies =
       (from c in exposureDoc.Descendants("company")
        let id = (int)c.Element("id")
        orderby id
        select new
        {
            Id = id,
            Regions = new HashSet<int>(
                from r in c.Elements("region")
                select (int)r),
        }).ToList();
    var events =
        from e in eventsDoc.Descendants("event")
        let id = (int)e.Element("id")
        orderby id descending
        select new
        {
            Id = id,
            Regions = from r in e.Elements("region")
                      select (int)r,
        };
    foreach (var evnt in events)
    {
        var affectedCompanies =
            from c in companies
            where c.Regions.Overlaps(evnt.Regions)
            select c.Id;
        if (affectedCompanies.Any())
            Console.WriteLine("{0} {1}", evnt.Id, String.Join(" ", affectedCompanies));
    }
    

    If you’re using .NET 3.5, you’ll need to change the query in the body of the loop a bit.

    var affectedCompanies =
       (from c in companies
        where c.Regions.Overlaps(evnt.Regions)
        select c.Id.ToString()).ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some xml documents I need to run queries on. I've created some
So, i have some question about xml Documents in Java. Can i get all
I have some XML/TEI documents, and i'm writing an XSLT 2.0 to extract their
I have the following collection in an XML document: <events> <event> <type>Downloaded</type> <result>Sucess</result> </event>
Currently I have some xml documents which are converted via xsl into html. The
I have some XML that looks something like this: <Root> <Documents> <Document id=1/> </Documents>
I have written some code that loads an XML document using an XmlDocument object
I have an XML document containing contact information as seen below: <contact type=individual> <firstname>Some</firstname>
I have some XML that is structured like this: <whatson> <productions> <production> <category>Film</category> </production>
I have some XML files that contain different function information. I am trying to

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.