Example usage for javax.xml.stream.events StartElement asStartElement

List of usage examples for javax.xml.stream.events StartElement asStartElement

Introduction

In this page you can find the example usage for javax.xml.stream.events StartElement asStartElement.

Prototype

public StartElement asStartElement();

Source Link

Document

Returns this event as a start element event, may result in a class cast exception if this event is not a start element.

Usage

From source file:org.jonross.coercion.v2.BinderSpec.java

/**
 *///ww w . j a  va2 s.co m

public void parse(Reader input) throws XMLStreamException {
    // Grab the first element in the binder file and verify that it's
    // our show; check for binder package name and class name.

    XMLEventReader reader = inputFactory.createXMLEventReader(input);
    StartElement start = nextStartElement(reader).asStartElement();

    if (!start.getName().equals(CO_UNMARSHALLER))
        throw new CoercionException(
                "Root element must be <" + CO_UNMARSHALLER.getLocalPart() + "> in namespace " + MY_NS);

    Attribute att = start.getAttributeByName(CO_PACKAGE_NAME);
    if (att != null)
        packageName = att.getValue();

    att = start.getAttributeByName(CO_CLASS_NAME);
    if (att != null)
        className = att.getValue();
    else
        throw new CoercionException("Root <unmarshaller> element is missing className attribute");

    root = parse(reader, start.asStartElement());
}