Android Question XML: Reading node text based on attributes

oliverm

Member
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"
CurrentRoom.NorthDescription=Text.ToString
Case "south"
CurrentRoom.SouthDescription=Text.ToString
Case "east"
CurrentRoom.eastDescription=Text.ToString
Case "west"
CurrentRoom.westDescription=Text.ToString
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?

Olly
 

oliverm

Member
Licensed User
Longtime User
Thanks for the input guys.

The XML looks likes this

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

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?

Olly
 
Upvote 0
Top