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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:55:19+00:00 2026-06-06T03:55:19+00:00

Im really struggling to get my head round this. Im using c#. I want

  • 0

Im really struggling to get my head round this.

Im using c#.

I want to get back an IEnumerable of products from an xml file.

Below is a sample of the xml structure.

I need to get a list of products that have the productEnriched custom attribute set as true.

Some products wont have any custom attribute section at all

my head has strated to hurt just thinking about it!

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://www.mynamespace.com" catalog-id="MvgCatalog">
    <product>
        <custom-attributes>
            <custom-attribute attribute-id="productEnriched">true</custom-attribute>
        </custom-attributes>
    </product>
</category>

thanks for any help

To clear things up i have added a few more items to the example xml

I need to get a list of products
only products that have a custom-attribute element with the attribute productEnriched and value of true
some products in the xml wont have any custom-attribute or custom-attributes elements
some products will have it but with a value of false
i just need a list of products where it exists and has a value of true

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://www.mynamespace.com" catalog-id="MvgCatalog">
    <product>
        <upc>000000000000</upc> 
        <productTitle>My product name</productTitle>
        <custom-attributes>
           <custom-attribute attribute-id="productEnriched">true</custom-attribute>
           <custom-attribute attribute-id="somethingElse">4</custom-attribute>
           <custom-attribute attribute-id="anotherThing">otherdata</custom-attribute>
        </custom-attributes>
    </product>
</category>
  • 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-06T03:55:20+00:00Added an answer on June 6, 2026 at 3:55 am

    I need to get a list of products only products that have a
    custom-attribute element with the attribute productEnriched and value
    of true some products in the xml wont have any custom-attribute or
    custom-attributes elements some products will have it but with a value
    of false i just need a list of products where it exists and has a
    value of true

    var xml = XElement.Load(@"your file.xml");
    XNamespace ns = "http://www.mynamespace.com";
    var products = xml.Elements(ns + "product");
    var filtered = products.Where(
        product =>
            product.Element(ns + "custom-attributes") != null &&
            product.Element(ns + "custom-attributes").Elements(ns + "custom-attribute")
            .Any(
                ca => 
                    ca.Value == "true" && 
                    ca.Attribute("attribute-id") != null && 
                    ca.Attribute("attribute-id").Value == "productEnriched"));
    

    By the way, your XMLs are not valid – your opening tag (catalog) does not match your closing tag (category).

    The format by itself is strange – is it your idea?

        <custom-attributes>
           <custom-attribute attribute-id="productEnriched">true</custom-attribute>
           <custom-attribute attribute-id="somethingElse">4</custom-attribute>
           <custom-attribute attribute-id="anotherThing">otherdata</custom-attribute>
        </custom-attributes>
    

    Why put an attribute name as an attribute value and attribute value as an element value? It looks bloated and kind of “reinvents” XML with no clear purpose.

    Why not:

        <custom-attributes>
           <custom-attribute productEnriched="true"/>
           <custom-attribute somethingElse="4"/>
           <custom-attribute anotherThing="otherdata"/>
        </custom-attributes>
    

    Or:

        <custom-attributes productEnriched="true" somethingElse="4" anotherThing="otherdata"/>
    

    Or perhaps just use elements:

        <product-parameters>
           <productEnriched>true</productEnriched>
           <somethingElse>4</somethingElse>
           <anotherThing>otherdata</anotherThing>
        </product-parameters>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really bad at Javascript and I'm struggling to get my head round it.
Really struggling to get this to work. I've declared the window from the xib
I'm really struggling to get my head around Drupal Form API...actually Drupal as a
Really struggling to figure this out. Just trying to take in data from php
really struggling to resolve this issue. using nhibernate Im trying to join two different
I'm really struggling to get my first AXIS SOAP client to work. I'm using
I'm getting this run-time error and I'm really struggling to get to the bottom
I am really struggling with this one. Below is an image of a layout
I'm really struggling to get my head around the idea of working with a
I'm really struggling to get this to work in xcode 4. I have one

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.