Example usage for javax.xml.stream XMLStreamReader getLocalName

List of usage examples for javax.xml.stream XMLStreamReader getLocalName

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

From source file:Main.java

public static void consumeStart(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException {
    while (xmlRdr.hasNext()) {
        if (xmlRdr.isStartElement() && xmlRdr.getLocalName().equals(elementName)) {
            xmlRdr.next();//w  w w . j  av a 2 s.  c  o  m
            return;
        }
        xmlRdr.next();
    }
    throw new IllegalStateException(
            "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'");
}

From source file:Main.java

public static void consumeEnd(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException {
    while (xmlRdr.hasNext()) {
        if (xmlRdr.isEndElement() && xmlRdr.getLocalName().equals(elementName)) {
            xmlRdr.next();/*from ww w  .java  2s.  c om*/
            return;
        }
        xmlRdr.next();
    }
    throw new IllegalStateException(
            "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'");
}

From source file:Main.java

/**
 * Test if reader is on a start tag named tagLocalName.
 *
 * @param reader       xml stream reader
 * @param tagLocalName tag local name/*from w ww  .  j  av  a2  s  .  c  o  m*/
 * @return true if reader is on a start tag named tagLocalName
 */
public static boolean isStartTag(XMLStreamReader reader, String tagLocalName) {
    return (reader.getEventType() == XMLStreamConstants.START_ELEMENT)
            && (reader.getLocalName().equals(tagLocalName));
}

From source file:Main.java

public static boolean isElement(XMLStreamReader xmlRdr, int eventType, String tagName) {
    int event = xmlRdr.getEventType();
    if (event == eventType) {
        String locName = xmlRdr.getLocalName();
        if (locName.equals(tagName))
            return true;
    }/*w w w  .jav a2 s  . co  m*/
    return false;
}

From source file:Main.java

private static void printName(XMLStreamReader xmlr, int eventType) {
    if (xmlr.hasName()) {
        System.out.println("HAS NAME: " + xmlr.getLocalName());
    } else {/*  ww  w  .ja v a 2 s  .co  m*/
        System.out.println("HAS NO NAME");
    }
}

From source file:Main.java

private static void process(XMLStreamReader reader) {
    int eventType = reader.getEventType();
    switch (eventType) {
    case XMLStreamConstants.START_ELEMENT:
        System.out.println("Start element: " + reader.getLocalName());
        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            String name = reader.getAttributeLocalName(i);
            String value = reader.getAttributeValue(i);
            System.out.println("\tAttribute name/value: " + name + "/" + value);
        }/*w ww .java 2  s . c o  m*/
        break;
    case XMLStreamConstants.END_ELEMENT:
        System.out.println("End element: " + reader.getLocalName());
        break;

    case XMLStreamConstants.CHARACTERS:
        System.out.println("Text: " + reader.getText());
        break;
    default:
        break;
    }
}

From source file:XMLStreamReaderDemo.java

private static void process(XMLStreamReader reader) {
    int eventType = reader.getEventType();
    switch (eventType) {
    case XMLStreamConstants.START_ELEMENT:
        System.out.println("Start element: " + reader.getLocalName());

        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            String name = reader.getAttributeLocalName(i);
            String value = reader.getAttributeValue(i);
            System.out.println("\tAttribute name/value: " + name + "/" + value);
        }//from w  w  w.  j a  v  a2s  .co m
        break;

    case XMLStreamConstants.END_ELEMENT:
        System.out.println("End element: " + reader.getLocalName());
        break;

    case XMLStreamConstants.CHARACTERS:
        System.out.println("Text: " + reader.getText());
        break;
    default:
        break;
    }
}

From source file:Main.java

private static void printName(XMLStreamReader xmlr, StringBuffer b) {
    if (xmlr.hasName()) {
        String prefix = xmlr.getPrefix();
        String uri = xmlr.getNamespaceURI();
        String localName = xmlr.getLocalName();
        printName(prefix, uri, localName, b);
    }/*from  w  w w.j  a v a 2s .co m*/
}

From source file:Main.java

public static boolean goToNextXBeforeY(XMLStreamReader reader, String X, String Y) throws XMLStreamException {
    while (reader.hasNext()) {
        int code = reader.next();
        if (code == XMLStreamReader.END_ELEMENT && reader.getLocalName().equals(Y)) {
            return false;
        }/*  www  .jav a2 s  . c  om*/
        if (code == XMLStreamReader.START_ELEMENT && reader.getLocalName().equals(X)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

private static void printName(XMLStreamReader xmlr, StringBuffer result) {
    if (xmlr.hasName()) {
        String prefix = xmlr.getPrefix();
        String uri = xmlr.getNamespaceURI();
        String localName = xmlr.getLocalName();
        printName(prefix, uri, localName, result);
    }//  ww w .  ja  v  a  2 s .  c o  m
}