Java XML Parse Stream parseValue(XMLStreamReader xmlRdr, String elementName)

Here you can find the source of parseValue(XMLStreamReader xmlRdr, String elementName)

Description

parse Value

License

Open Source License

Declaration

public static String parseValue(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException 

Method Source Code


//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();// ww w  .java2s  .co m
            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());
    }
}

Related

  1. parseNumber(XMLEventReader stream)
  2. parser(InputStream inputStream)
  3. parseStream(InputStream stream, boolean validate, boolean expandEntityRefs)
  4. parseStreamToXML(InputStream in)
  5. parseText(XMLStreamReader parser)
  6. parseXml(InputStream in)
  7. parseXml(InputStream in)
  8. parseXML(InputStream in)
  9. parseXml(InputStream inputStream, boolean validating)