tags:

views:

50

answers:

2

I have an XML file that looks like this.

<Almond>    Roasted Almonds,Almond Extract,Almond Sauce,Almond Milk,Almond Cake,Almond Ice Cream,Almond Paste </Almond>
<American Cheese>   MilkWhey,Cheese Dip,Sliced Cheese </American Cheese>
<Apple> Apple Sauce,Apple Pie,Pear,Apple Juice,Apple Cider,Apple Butter   </Apple>
<Avocado>   Guacamole,California Sushi Rolls,Hass Avocado,Avocado Oil </Avocado>
<Banana>    Banana Bread,Banana Cream Pie,Banana Split,Banana Pudding </Banana>

do you suggest a different way to format this?

i will need to get every food that is associated with almond, with american cheese, apple etc..

i will be reading the data with vb.net

+2  A: 

Instead of having lines of command separated values, I'd have child tags called <Item> or something so the parser could have a shot at handling them. It's more verbose, but better XML.

If XML doesn't work here I'd propose something less verbose like JSON. I don't see that tags and metadata are doing you much good here.

duffymo
A: 

From your XML you appear to need some kind of "tagging". If we assume that your xml is intended to store ingredients, then why not have a tag called <ingredient/>

here is a sample of what the XML could look like:

<recipelist>
    <recipe name="Roasted Almonds">
        <ingredients>
            <ingredient>Almond</ingredient>
        </ingredients>
    </recipe>
    <recipe name="Almond Extract">
        <ingredients>
            <ingredient>Almond</ingredient>
            <ingredient>some other</ingredient>
        </ingredients>
    </recipe>
</recipelist>

Then you can use LinQ or some other XML query language to query for the same results you have above. A sample XPath query would be something as follows:

//recipelist/recipe[ingredients/ingredient/text()='Almond']/@name

This would give all the Recipes that have "Almond" as an ingredient. This would also provide a more flexible XML format for other purposes and is easier to generate from a database.

funkymushroom