background image

Returning String Representations

<< Stepping Through Events | cursor2event Sample >>
<< Stepping Through Events | cursor2event Sample >>
104
S
TREAMING
API
FOR
XML
printPIData(xmlr);
printComment(xmlr);
}
}
Note that
next()
just returns an integer constant corresponding to the event
underlying the current cursor location. The application calls the relevant function
to get more information related to the underlying event. There are various acces-
sor methods which can be called when the cursor is at particular event.
Returning String Representations
Because the
next()
method only returns integers corresponding to underlying
event types, you typically need to map these integers to string representations of
the events; for example:
public final staticString getEventTypeString(inteventType)
{
switch(eventType)
{
case XMLEvent.START_ELEMENT:
return "START_ELEMENT";
case XMLEvent.END_ELEMENT:
return "END_ELEMENT";
case XMLEvent.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLEvent.CHARACTERS:
return "CHARACTERS";
case XMLEvent.COMMENT:
return "COMMENT";
case XMLEvent.START_DOCUMENT:
return "START_DOCUMENT";
case XMLEvent.END_DOCUMENT:
return "END_DOCUMENT";
case XMLEvent.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLEvent.ATTRIBUTE:
return "ATTRIBUTE";
case XMLEvent.DTD:
return "DTD";
case XMLEvent.CDATA:
return "CDATA";
case XMLEvent.SPACE: