Bug? iXmlSax - EndElement text node error

Scott Bartgis

Member
Licensed User
Longtime User
I come from the XML DOM parsing world, but rather than wait or invent something from scratch, I am using SAX in my application.

My question is with the text values received in an EndElement event. It seems to include the text node with every end element, if the last element had one.

Example XML String:

<SERVER PRODUCT="model1" ZONE="1" VER="1.0" ><GUI><PLAYER><TIME TYPE="elapsed">123</TIME></PLAYER></GUI></SERVER>

When run through SAX, here is what is logged:

{StartElement} SERVER attributes: 3
{StartElement} GUI attributes: 0
{StartElement} PLAYER attributes: 0
{StartElement} TIME attributes: 1
{EndElement} TIME text: 123
{EndElement} PLAYER text: 123
{EndElement} GUI text: 123
{EndElement} SERVER text: 123

And here is the code:
B4X:
Sub XMLParser_StartElement (Uri As String, element As String, Attributes As Map)
    Log("{StartElement} " & element & " attributes: " & Attributes.Size)
End Sub

Sub XMLParser_EndElement (Uri As String, element As String, xText As StringBuilder)
    Log("{EndElement} " & element & " text: " & xText.)
End Sub

Shouldn't the text be empty for PLAYER, GUI, and SERVER?
 

Scott Bartgis

Member
Licensed User
Longtime User
Just had an idea to try out other text nodes in the child elements, and as I feared, those are ignored. Only the last text is being provided.

XML: SERVER PRODUCT="model1" ZONE="1" VER="1.0" ><GUI>Hello world!<PLAYER><TIME TYPE="elapsed">123</TIME></PLAYER></GUI></SERVER>

Output is the exact same as above example. "Hello world!" never comes back in the EndElement.

I am fairly sure that this XML structure is allowed.

http://stackoverflow.com/questions/...tain-text-and-child-elements-at-the-same-time
 
Top