Reputation: 45
I have this XML problem that is bugging me today, and I can't find a solution because I don't know how to phrase it. My XML file looks like this:
<TEST>
<ITEM_ID>0123
<ITEM_SIZE>Medium</ITEM_SIZE>
<ITEM_COLOR>Red</ITEM_COLOR>
</ITEM_ID>
</TEST>
Everything works fine (i can find a random element, display or erase it) and can get the information I want, but the only thing that I cannot access the with myXML_XML.ITEM_ID[0], which shoud say "0123". I get nothing, no error, nothing. When I check myXML_XML.ITEM_ID[0].ITEM_SIZE (when put in a String Var, I get "Medium" ).
I thought perhaps the XML was misleading so I tried with another file:
<TEST>
<ITEM_ID REF="0123">
<ITEM_SIZE>Medium</ITEM_SIZE>
<ITEM_COLOR>Red</ITEM_COLOR>
</ITEM_ID>
</TEST>
Which gave me the same results, when checking for myXML_XML.ITEM_ID[0].REF or myXML_XML.ITEM_ID[0].REF.text
Anyone kind enough to enlighten me?
Upvotes: 0
Views: 736
Reputation: 930
Your first XML schema seems to be a little off, but valid nonetheless. You might want to try children() method of the nodes.
myXML_XML.ITEM_ID[0].children()[0] // This is the text node
In the other example, which is more readable in fact, you should use @ sign for accessing attributes
myXML_XML.ITEM_ID[0].@REF
Here is a complete example:
var test:XML = new XML(
<foo>
<bar id="4444">
efghi
<baz>1234</baz>
<quux>6789</quux>
</bar>
<bar id="4445">
zxcv
<baz>4567</baz>
<quux>9876</quux>
</bar>
</foo>
);
trace(test.bar[0].children()[0]); // efghi
trace(test.bar[1].@id); // 4445
Upvotes: 1