我有一个如下所示的XML文件。
<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>你有没有建议一种不同的格式化方法?
我需要得到与杏仁,美国奶酪,苹果等有关的每一种食物。
我将使用vb.net读取数据
发布于 2009-12-30 02:27:22
我不再使用命令行来分隔值,而是使用名为的子标记或其他名称,这样解析器就可以尝试处理它们。它更冗长,但XML更好。
如果XML在这里不起作用,我建议使用不那么冗长的东西,比如JSON。我看不出标签和元数据在这里对你有多大的好处。
发布于 2009-12-30 06:14:33
在您的XML中,您似乎需要某种“标记”。如果我们假设xml是用来存储配料,那么为什么不使用一个名为<ingredient/>的标记呢
下面是XML可能的样子的示例:
<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>然后,您可以使用LinQ或其他一些XML查询语言来查询与上面相同的结果。示例XPath查询将如下所示:
//recipelist/recipe[ingredients/ingredient/text()='Almond']/@name这将给出所有以“杏仁”为成分的食谱。这也将为其他用途提供更灵活的XML格式,并且更容易从数据库生成。
https://stackoverflow.com/questions/1976088
复制相似问题