background image

Returning String Representations

<< Stepping through Events | Cursor-to-Event Example >>
<< Stepping through Events | Cursor-to-Event Example >>

Returning String Representations

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 static String getEventTypeString(int eventType) {
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:
return
"SPACE";
}
return
"UNKNOWN_EVENT_TYPE , " + eventType;
}
Building and Running the Cursor Example Using NetBeans IDE
Follow these instructions to build and run the Cursor example on your Application Server
instance using the NetBeans IDE.
1. In NetBeans IDE, select File
Open Project.
2. In the Open Project dialog, navigate to the tut-install/javaeetutorial5/examples/stax/
directory.
3. Select the cursor folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
Example Code
The Java EE 5 Tutorial · September 2007
570