Android Question XML: Reading node text based on attributes


Licensed User
Longtime User
Hi All

I want to read the text within an XML node based on its attributes. The problem is that the node text bit is accessible in the EndElement sub routine and the attributes are available in the StartElement bit.

In my example we have a node called "exit" which has an attribute of Title which is either North, South, East or West. I want to read that nodes Text in to a given variable, based on the title name.

Here's my code;
sub xmlparser_endelement(blah)
If Name.ToLowerCase="exit" Then
If xmlParser.Parents.IndexOf("story") > -1 Then
Select Attributes.GetValue2("","title")
Case "north"
Case "south"
Case "east"
Case "west"
End Select
End If
End If

end sub
You can see that the line "Select Attributes.GetValue2("","title")" would fail because attributes aren't available in the endelement, but "Text" isn't available in Startelement.

Any ideas how I can get that working?



Licensed User
Longtime User
Thanks for the input guys.

The XML looks likes this

<room title="First Room">
-------This room is really scary
---<exit title="north">
---------A blue door

So the Description node of the EXIT node with the title of NORTH needs to go in to CurrentRoom.NorthDescription. If that makes sense.

Erel, how can I define a global attributes variable? I mean, can I just Dim it in the global section and will the Start sub then use that rather than it's own one?

Upvote 0