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>
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?
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:
Or:
Or perhaps just use elements: