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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:56:30+00:00 2026-05-10T23:56:30+00:00

I have an XML feed (which I don’t control) and I am trying to

  • 0

I have an XML feed (which I don’t control) and I am trying to figure out how to detect the volume of certain attribute values within the document.

I am also parsing the XML and separating attributes into Arrays (for other functionality)

Here is a sample of my XML

<items> <item att1='ABC123' att2='uID' /> <item att1='ABC345' att2='uID' /> <item att1='ABC123' att2='uID' /> <item att1='ABC678' att2='uID' /> <item att1='ABC123' att2='uID' /> <item att1='XYZ123' att2='uID' /> <item att1='XYZ345' att2='uID' /> <item att1='XYZ678' att2='uID' /> </items> 

I want to find the volume nodes based on each att1 value. Att1 value will change. Once I know the frequency of att1 values I need to pull the att2 value of that node.

I need to find the TOP 4 items and pull the values of their attributes.

All of this needs to be done in C# code behind.

If I was using Javascript I would create an associative array and have att1 be the key and the frequency be the value. But since I’m new to c# I don’t know how to duplicate this in c#.

So I believe, first I need to find all unique att1 values in the XML. I can do this using:

IEnumerable<string> uItems = uItemsArray.Distinct(); // Where uItemsArray is a collection of all the att1 values in an array 

Then I get stuck on how I compare each unique att1 value to the whole document to get the volume stored in a variable or array or whatever data set.

Here is the snippet I ended up using:

        XDocument doc = XDocument.Load(@'temp/salesData.xml');         var topItems = from item in doc.Descendants('item')                     select new                     {                         name = (string)item.Attribute('name'),                         sku = (string)item.Attribute('sku'),                         iCat = (string)item.Attribute('iCat'),                         sTime = (string)item.Attribute('sTime'),                         price = (string)item.Attribute('price'),                         desc = (string)item.Attribute('desc')                      } into node                     group node by node.sku into grp                     select new {                          sku = grp.Key,                         name = grp.ElementAt(0).name,                         iCat = grp.ElementAt(0).iCat,                         sTime = grp.ElementAt(0).sTime,                         price = grp.ElementAt(0).price,                         desc = grp.ElementAt(0).desc,                         Count = grp.Count()                      };          _topSellers = new SalesDataObject[4];         int topSellerIndex = 0;         foreach (var item in topItems.OrderByDescending(x => x.Count).Take(4))         {             SalesDataObject topSeller = new SalesDataObject();             topSeller.iCat = item.iCat;             topSeller.iName = item.name;             topSeller.iSku = item.sku;             topSeller.sTime = Convert.ToDateTime(item.sTime);             topSeller.iDesc = item.desc;             topSeller.iPrice = item.price;             _topSellers.SetValue(topSeller, topSellerIndex);             topSellerIndex++;         }  

Thanks for all your help!

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T23:56:30+00:00Added an answer on May 10, 2026 at 11:56 pm

    If you have the values, you should be able to use LINQ’s GroupBy…

            XDocument doc = XDocument.Parse(xml);         var query = from item in doc.Descendants('item')                     select new                     {                         att1 = (string)item.Attribute('att1'),                         att2 = (string)item.Attribute('att2') // if needed                     } into node                     group node by node.att1 into grp                     select new { att1 = grp.Key, Count = grp.Count() };          foreach (var item in query.OrderByDescending(x=>x.Count).Take(4))         {             Console.WriteLine('{0} = {1}', item.att1, item.Count);         } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-driven site that includes an XML stock feed, which is remotely
Do developers have to put certain/extra elements in the feed's XML file or attributes
I'm trying to parse an Atom feed programmatically. I have the atom XML downloaded
I have xml where some of the element values are unicode characters. Is it
I have a cron job that runs every hour. It accesses an xml feed.
I have an XML feed that looks like this: <?xml version=1.0 encoding=UTF-8?> <productFeed version=1.0
I am really struggling on this. I have an XML feed: <?xml version=1.0 encoding=ISO-8859-1?>
I have xml files I want to read in and store in the database.
I have XML files in a directory that I wish to get over to
I have XML with a value like the following: <products> <product id=1 name=All Products>

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.