Writing XML

hello. Im wondering if I can add to the following example:

var xml:XML = 
        <foo>
            <bar>text1</bar>
            <bar>text2</bar>
        </foo>;

another
<bar>text1</bar>
tag.
How do I do it? And how do I reference it and not reference the other similar tags if I DONT KNOW the number of them?
For example how can I change the “text” of a bar if I dont know the number of the bar tags?