Example usage for javax.xml.stream XMLStreamReader isStartElement

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

Introduction

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

Prototype

public boolean isStartElement();

Source Link

Document

Returns true if the cursor points to a start tag (otherwise false)

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();//from   ww w.  ja  v  a2  s .com
            return;
        }
        xmlRdr.next();
    }
    throw new IllegalStateException(
            "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'");
}

From source file:Main.java

/**
 * Skips the complete content of the element at the specified reader's
 * cursor. The reader's current event type must be START_ELEMENT, otherwise
 * this method will have no effect. Upon completion, the reader's cursor
 * will be at the END_ELEMENT event for the skipped element.
 * //  ww w .j  a v  a2s  . c  o  m
 * @param reader An XML stream reader currently in the START_ELEMENT event.
 */
public static final void skipElement(XMLStreamReader reader) throws XMLStreamException {

    if (reader.isStartElement()) {

        skipElementContent(reader);

    }

}

From source file:it.govpay.core.utils.client.SOAPUtils.java

public static Object unmarshal(InputStream is, Schema schema)
        throws JAXBException, SAXException, IOException, XMLStreamException {

    XMLStreamReader xsr = xif.createXMLStreamReader(is);

    boolean isBody = false;
    while (!isBody) {
        xsr.nextTag();/*w  w  w . j  a v a 2s  . com*/
        if (xsr.isStartElement()) {
            String local = xsr.getLocalName();
            isBody = local.equals("Body");
        }
    }

    xsr.nextTag();
    if (!xsr.isStartElement()) {
        // Body vuoto
        return null;
    } else {
        return JaxbUtils.unmarshal(xsr, schema);
    }
}

From source file:Main.java

/**
 * Skips an element's complete content. This method assumes that the
 * <code>START_ELEMENT</code> has already be passed, and when it terminates,
 * the stream will be positioned at the <code>END_ELEMENT</code>.
 * //ww  w.ja  va 2s. c o m
 * @param reader The stream reader to read.
 * @throws XMLStreamException If an error occurs reading the stream.
 */
public static final void skipElementContent(XMLStreamReader reader) throws XMLStreamException {

    int depth = 0;
    while (depth >= 0) {

        reader.next();
        if (reader.isStartElement()) {

            depth++;

        } else if (reader.isEndElement()) {

            depth--;

        }

    }

}

From source file:Main.java

public boolean accept(XMLStreamReader reader) {
    if (!reader.isStartElement() && !reader.isEndElement()) {
        return false;
    } else {/*w w  w  .j a  v a2  s.c  om*/
        return true;
    }
}

From source file:com.predic8.membrane.core.interceptor.balancer.XMLElementSessionIdExtractor.java

private boolean isSessionIdElement(XMLStreamReader reader) {
    return reader.isStartElement() && localName.equals(reader.getLocalName())
            && (namespace == null || namespace.equals(reader.getNamespaceURI()));
}

From source file:com.predic8.membrane.core.config.AbstractXmlElement.java

protected void move2RootElementIfNeeded(XMLStreamReader token) throws XMLStreamException {
    if (token.getEventType() == XMLStreamReader.START_DOCUMENT) {
        while (!token.isStartElement()) {
            token.next();/*w w w.ja v a2  s  . c  o m*/
        }
    }

}

From source file:com.predic8.membrane.core.config.AbstractXmlElement.java

/**
 * Needed to resolve interceptor IDs into interceptor beans
 *///from w ww .  ja  v  a2s .  c  o m

public XMLElement parse(XMLStreamReader token) throws Exception {
    move2RootElementIfNeeded(token);
    log.debug("<" + token.getLocalName() + ">");
    parseAttributes(token);
    while (token.hasNext()) {
        token.next();
        if (token.isStartElement()) {
            parseChildren(token, token.getName().getLocalPart());
        } else if (token.isCharacters()) {
            parseCharacters(token);
        } else if (token.isEndElement()) {
            log.debug("</" + token.getLocalName() + ">");
            break;
        }
    }
    doAfterParsing();
    return this;
}

From source file:com.predic8.membrane.core.config.AbstractXmlElement.java

protected void parseChildren(XMLStreamReader token, String child) throws Exception {
    int count = 0;
    while (true) { // ignore child
        token.next();//from ww  w . j  av  a2 s  .c  o m
        if (token.isEndElement() && child.equals(token.getName().getLocalPart())) {
            if (count == 0)
                return;
            count--;
        } else if (token.isStartElement() && child.equals(token.getName().getLocalPart())) {
            count++;
        }
    }
}

From source file:com.predic8.membrane.core.http.xml.Response.java

@Override
protected void parseChildren(XMLStreamReader token, String child) throws Exception {
    if (Headers.ELEMENT_NAME.equals(child)) {
        headers = (Headers) new Headers().parse(token);
    } else if ("status".equals(child)) {
        statusCode = Integer/*from  www .jav a  2 s  . c o m*/
                .parseInt(StringUtils.defaultIfBlank(token.getAttributeValue("", "status-code"), "0"));
        statusMessage = "";
        while (token.hasNext()) {
            token.next();
            if (token.isStartElement()) {
                parseChildren(token, token.getName().getLocalPart());
            } else if (token.isCharacters()) {
                statusMessage += token.getText();
            } else if (token.isEndElement()) {
                break;
            }
        }
    }
}