You can use Foods XML files, such as the
foods.xml
file we have created
in this example, just as you would use a Pantry
native file (the format used by the
master
file. For example:
Example 5.5. Use a Foods XML file as you would use a Pantry native file
$
pantry --name Clif --print traits-nuts foods.xml
Clif Bar, Oatmeal Raisin Walnut Group: Snacks 1.0 bar (68g) Nutrient Amount %G %TOT ------------------------------------------------------ Calories 240 kcal 12 100 Total Fat 5 g 8 100 Saturated Fat 1 g 5 100 Cholesterol 0 mg 0 NA Sodium 130 mg 5 100 Total Carbohydrate 43 g 14 100 Dietary Fiber 5 g 20 100 Sugars 20 g NG 100 Protein 10 g 20 100 Vitamin A 1500 IU 30 100 Vitamin C 60 mg 100 100 Calcium 250 mg 25 100 Iron 5 mg 25 100
However, I recommend adding the foods to a Pantry
native file, because you will find
it most convenient if the foods you create are
mingled with the other foods you use, either in the
master
file or in a
quick
file, as we discussed
earlier.[13]
For example, to add the Clif Bar to my
master
file, I simply run
pantry --add master foods.xml
.
You may insert comments into your XML file.
In addition, you will probably format your XML
in a certain way by using tabs and newlines.
However, if you make changes to the XML file
using --add
,
--edit
, or
--delete
, Pantry will
destroy this formatting and
lose the comments. You will also find that, if
you use --add
,
--edit
, or
--delete
, Pantry will rearrange
the order of the foods in your XML file and will
even rearrange the order of the attributes.
For the time being,[14]
one solution to this is to use
only the comment
attribute if you
wish to comment on foods. Also, you can simply refrain
from making changes to the file using Pantry; Pantry
will not destroy data in XML files if it only reading
data from them.
[13] In addition, Foods XML files are slower to process than Pantry native files. If a Foods XML file contains just a few foods, the difference is not noticeable. However, for more than several dozen foods, the speed difference might begin to add up. That is why Pantry does not use XML as its native file format.
[14] This problem likely will be fixed in a future release, but because of the intended use of Foods XML files as being primarily a way to import new foods, fixing this issue is a low priority.