Java Utililty Methods XMLStreamReader

List of utility methods to do XMLStreamReader

Description

The list of methods to do XMLStreamReader are organized into topic(s).

Method

StringprintEvent(XMLStreamReader xmlr)
print Event
StringBuffer b = new StringBuffer();
b.append("EVENT:[" + xmlr.getLocation().getLineNumber() + "][" + xmlr.getLocation().getColumnNumber()
        + "] ");
b.append(getName(xmlr.getEventType()));
b.append(" [");
switch (xmlr.getEventType()) {
case XMLStreamReader.START_ELEMENT:
    b.append("<");
...
voidprintEvent(XMLStreamReader xmlr, boolean showEvents)
print Event
if (showEvents) {
    System.out.print("EVENT:[" + xmlr.getLocation().getLineNumber() + "]["
            + xmlr.getLocation().getColumnNumber() + "] [" + getEventTypeName(xmlr.getEventType()) + "]");
    System.out.print(" [");
switch (xmlr.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
    System.out.print("<");
...
voidprintLiterally(final PrintStream os, final XMLStreamReader xmlReader)
print Literally
final int start = xmlReader.getTextStart();
final int length = xmlReader.getTextLength();
os.print(new String(xmlReader.getTextCharacters(), start, length));
voidprintText(XMLStreamReader xmlr)
Print out text
if (xmlr.hasText()) {
    System.out.println("HAS TEXT: " + xmlr.getText());
} else {
    System.out.println("HAS NO TEXT");
voidreadEndTag(XMLStreamReader reader, String localName)
read End Tag
reader.nextTag();
reader.require(XMLStreamConstants.END_ELEMENT, null, localName);
StringreadEvent(XMLStreamReader reader)
read Event
StringBuffer buf = new StringBuffer();
int type = reader.getEventType();
switch (type) {
case XMLStreamConstants.START_DOCUMENT:
    break;
case XMLStreamConstants.END_DOCUMENT:
    break;
case XMLStreamConstants.START_ELEMENT:
...
StringreadTextWithNodes(XMLStreamReader xsr, Map nodeIdToOffsetMap)
Processes the TextWithNodes element from this XMLStreamReader, returning the text content of the document.
StringBuffer textBuf = new StringBuffer(20480);
int eventType;
while ((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
    switch (eventType) {
    case XMLStreamConstants.CHARACTERS:
        textBuf.append(xsr.getTextCharacters(), xsr.getTextStart(), xsr.getTextLength());
        break;
    case XMLStreamConstants.START_ELEMENT:
...
voidskip(XMLStreamReader parser)
skip
while (parser.hasNext()) {
    int eventType = parser.next();
    if (eventType == XMLStreamConstants.START_ELEMENT) {
        skip(parser);
    } else if (eventType == XMLStreamConstants.END_ELEMENT) {
        return;
voidskip(XMLStreamReader parser)
Skips a tag or subtree.
assert parser != null;
int level = 1;
while (next(parser)) {
    int event = parser.getEventType();
    if (event == XMLStreamConstants.START_ELEMENT) {
        level++;
    } else if (event == XMLStreamConstants.END_ELEMENT) {
        level--;
...
intskipEventsTo(int targetEvent, XMLStreamReader parser)
skip Events To
int eventType = 0;
while (parser.hasNext()) {
    eventType = parser.next();
    if (eventType == targetEvent)
        return eventType;
return eventType;