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?
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 nodeIn the other example, which is more readable in fact, you should use @ sign for accessing attributes
myXML_XML.ITEM_ID[0].@REFHere is a complete example: