Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class Main {
    public static String parseValue(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException {
        String val = null;
        while (true) {
            xmlRdr.next();
            int event2 = xmlRdr.getEventType();
            if (event2 == XMLStreamConstants.CHARACTERS) {
                val = xmlRdr.getText();
            } else if (event2 == XMLStreamConstants.END_ELEMENT && xmlRdr.getLocalName().equals(elementName)) {
                return val;
            }
        }
    }

    public static String parseValue(XMLStreamReader xmlRdr) throws XMLStreamException {
        // consume start tag
        xmlRdr.next();
        String val = null;

        if (xmlRdr.getEventType() == XMLStreamConstants.CHARACTERS) {
            val = xmlRdr.getText();
            xmlRdr.next();
        }
        skipToEndElement(xmlRdr);
        return val;
    }

    public static void skipToEndElement(XMLStreamReader xmlRdr) throws XMLStreamException {
        do {
            if (xmlRdr.getEventType() == XMLStreamConstants.END_ELEMENT) {
                break;
            }
            xmlRdr.next();
        } while (xmlRdr.hasNext());
    }
}