|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.schmant.support.xml.stax.StAXSupport
public final class StAXSupport
This is a support class for StAX XML parsing.
Method Summary | |
---|---|
static void |
assertEndElementEvent(XMLEvent xe,
String elementName)
Assert that the event is an end element event for the specified XML tag name. |
static void |
assertEventOfType(XMLEvent xe,
Class<? extends XMLEvent> c)
Assert that the event is of the specified type. |
static void |
assertStartElementEvent(XMLEvent xe,
String elementName)
Assert that the event is a start element event for the specified XML tag name. |
static StartElement |
findElementInScope(XMLEventReader r,
QName scope,
QName... elements)
Search for any of the named elements within the scope of an element. |
static StartElement |
findElementInScope(XMLEventReader r,
String scope,
String... localNames)
Search for any of the named elements within the scope of an element. |
static StartElement |
findElementInScopeOrNull(XMLEventReader r,
QName scope,
QName... elements)
Search for any of the named elements within the scope of an element, returning null if no such element was found. |
static StartElement |
findElementInScopeOrNull(XMLEventReader r,
String scope,
String... localNames)
Search for any of the named elements within the scope of an element, returning null if no such element was found. |
static String |
getAttribute(StartElement se,
String attributeName)
Get the named attribute. |
static String |
getAttributeOrNull(StartElement se,
String attributeName)
Get the named attribute if it exists. |
static String |
getElementText(XMLEventReader xer,
QName elementName)
Get the text from the next occurrence of the named element. |
static String |
getElementText(XMLEventReader xer,
String localPart)
Get the text from the next occurrence of the named element. |
static XMLEvent |
getNextEvent(XMLEventReader xer)
Get the next interesting event (comments are ignored). |
static XMLEvent |
getNextEventIgnoreCharacters(XMLEventReader xer)
Get the next non-comment and non-characters event. |
static XMLEvent |
getNextEventOrNull(XMLEventReader xer)
Get the next event, returning null if the end of the XML stream
is reached. |
static StartElement |
getNextStartElement(XMLEventReader xer)
Get the next StartElement event. |
static StartElement |
getNextStartElementOrNull(XMLEventReader xer)
Get the next start element, returning null if the end of the file
is encountered. |
static String |
getNextText(XMLEventReader xer)
Get the next text. |
static StartElement |
goToElement(XMLEventReader xer,
QName name)
Go to the next occurrence of the named element. |
static StartElement |
goToElement(XMLEventReader xer,
String localName)
Go to the next occurrence of the named element. |
static StartElement |
goToElementOrNull(XMLEventReader xer,
QName name)
Go to the next occurrence of the named element. |
static StartElement |
goToElementOrNull(XMLEventReader xer,
String localName)
Go to the next occurrence of the named element. |
static XMLEvent |
goToEvent(XMLEventReader r,
int... eventTypes)
Go to the next event that is of any of the supplied event types. |
static XMLEvent |
goToEventOrNull(XMLEventReader r,
int... eventTypes)
Go to the next event that is of any of the supplied event types. |
static boolean |
isEventOfType(XMLEvent xe,
Class<? extends XMLEvent> c)
Check if the StAX event is of the supplied type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static XMLEvent getNextEventOrNull(XMLEventReader xer) throws XMLStreamException
null
if the end of the XML stream
is reached. Comments are skipped and not returned.
xer
- The event reader.
null
if at EOF.
XMLStreamException
- On errors.public static XMLEvent getNextEvent(XMLEventReader xer) throws XMLStreamException, SchmantException
xer
- The event reader.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.public static XMLEvent getNextEventIgnoreCharacters(XMLEventReader xer) throws XMLStreamException, SchmantException
xer
- The event reader.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.public static XMLEvent goToEventOrNull(XMLEventReader r, int... eventTypes) throws XMLStreamException
r
- The event reader.eventTypes
- The event types to look for.
null
if none of the events were found
before the end of the document.
XMLStreamException
- On errors.public static XMLEvent goToEvent(XMLEventReader r, int... eventTypes) throws XMLStreamException, SchmantException
r
- The event reader.eventTypes
- The event types to look for.
XMLStreamException
- On errors.
SchmantException
- If none of the event types were found before
the end of the document.public static StartElement getNextStartElementOrNull(XMLEventReader xer) throws XMLStreamException
null
if the end of the file
is encountered.
xer
- The event reader.
null
if at EOF.
XMLStreamException
- On errors.public static StartElement getNextStartElement(XMLEventReader xer) throws XMLStreamException, SchmantException
StartElement
event.
xer
- The event reader.
StartElement
event.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.public static StartElement goToElement(XMLEventReader xer, QName name) throws XMLStreamException, SchmantException
xer
- The event reader.name
- The name of the element.
StartElement
for the element.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached before the element is found.public static StartElement goToElement(XMLEventReader xer, String localName) throws XMLStreamException, SchmantException
xer
- The event reader.localName
- The local name of the element.
StartElement
for the element.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached before the element is found.public static StartElement goToElementOrNull(XMLEventReader xer, QName name) throws XMLStreamException
xer
- The event reader.name
- The name of the element.
StartElement
for the element or null
if
EOF is found without finding the element.
XMLStreamException
- On errors.public static StartElement goToElementOrNull(XMLEventReader xer, String localName) throws XMLStreamException
xer
- The event reader.localName
- The local name of the element.
StartElement
for the element or null
if
EOF is found without finding the element.
XMLStreamException
- On errors.public static String getNextText(XMLEventReader xer) throws XMLStreamException, SchmantException
xer
- The event reader.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.public static String getElementText(XMLEventReader xer, QName elementName) throws XMLStreamException, SchmantException
xer
- The event reader.elementName
- The element name.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.getElementText(XMLEventReader, String)
public static String getElementText(XMLEventReader xer, String localPart) throws XMLStreamException, SchmantException
The element must be text only, otherwise strange things may happen.
xer
- The event reader.localPart
- The element name.
XMLStreamException
- On errors.
SchmantException
- If EOF is reached.getElementText(XMLEventReader, QName)
public static boolean isEventOfType(XMLEvent xe, Class<? extends XMLEvent> c)
xe
- The event.c
- The type.
true
if the event is of the specified type.public static void assertEventOfType(XMLEvent xe, Class<? extends XMLEvent> c) throws SchmantException
xe
- The StAX event.c
- The type.
SchmantException
- If the event is of any other type.public static void assertStartElementEvent(XMLEvent xe, String elementName) throws SchmantException
xe
- The event.elementName
- The tag name.
SchmantException
- If the event is of any other type or if it is a
start event for any other tag.public static void assertEndElementEvent(XMLEvent xe, String elementName) throws SchmantException
xe
- The event.elementName
- The tag name.
SchmantException
- If the event is of any other type or if it is a
end event for any other tag.public static StartElement findElementInScopeOrNull(XMLEventReader r, QName scope, QName... elements) throws XMLStreamException
null
if no such element was found.
r
- The stream reader.scope
- The name of the scope.elements
- The names of elements to look for.
null
if the end tag for
the scope was found without finding any of the elements.
XMLStreamException
- On parsing errors from the underlying StAX
parserpublic static StartElement findElementInScope(XMLEventReader r, QName scope, QName... elements) throws XMLStreamException, SchmantException
r
- The stream reader.scope
- The name of the scope.elements
- The names of elements to look for.
XMLStreamException
- On parsing errors from the underlying StAX
parser
SchmantException
- If none of the elements were found in the
given scope.public static StartElement findElementInScopeOrNull(XMLEventReader r, String scope, String... localNames) throws XMLStreamException
null
if no such element was found.
r
- The stream reader.scope
- The name of the scope.localNames
- The names of elements to look for.
null
if the end tag for
the scope was found without finding any of the elements.
XMLStreamException
- On parsing errors from the underlying StAX
parserpublic static StartElement findElementInScope(XMLEventReader r, String scope, String... localNames) throws XMLStreamException, SchmantException
r
- The stream reader.scope
- The name of the scope.localNames
- The names of elements to look for.
XMLStreamException
- On parsing errors from the underlying StAX
parser
SchmantException
- If none of the elements were found in the
given scope.public static String getAttributeOrNull(StartElement se, String attributeName)
se
- The start element event to get the attribute from.attributeName
- The attribute name.
null
if the attribute does
not exist.public static String getAttribute(StartElement se, String attributeName) throws SchmantException
se
- The start element event to get the attribute from.attributeName
- The attribute name.
SchmantException
- If the attribute does not exist.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |