public class StaxParserUtil extends Object
Constructor and Description |
---|
StaxParserUtil() |
Modifier and Type | Method and Description |
---|---|
static XMLEvent |
bypassElementBlock(XMLEventReader xmlEventReader)
Bypass an entire XML element block.
|
static void |
bypassElementBlock(XMLEventReader xmlEventReader,
String tag)
Bypass an entire XML element block from startElement to endElement.
|
static String |
getAttributeValue(Attribute attribute)
Given an
Attribute , get its trimmed value |
static String |
getAttributeValue(StartElement startElement,
String tag)
Get the Attribute value
|
static boolean |
getBooleanAttributeValue(StartElement startElement,
String tag)
Get the Attribute value
|
static boolean |
getBooleanAttributeValue(StartElement startElement,
String tag,
boolean defaultValue)
Get the Attribute value
|
static Element |
getDOMElement(XMLEventReader xmlEventReader)
Given that the
XMLEventReader is in XMLStreamConstants.START_ELEMENT mode, we parse into a DOM
Element |
static String |
getElementText(XMLEventReader xmlEventReader)
Get the element text.
|
static String |
getEndElementName(EndElement endElement)
Return the name of the end element
|
static String |
getLineColumnNumber(Location location)
Given a
Location , return a formatted string [lineNum,colNum] |
static EndElement |
getNextEndElement(XMLEventReader xmlEventReader)
Get the next
EndElement |
static XMLEvent |
getNextEvent(XMLEventReader xmlEventReader)
Get the next xml event
|
static StartElement |
getNextStartElement(XMLEventReader xmlEventReader)
Get the next
StartElement |
static String |
getStartElementName(StartElement startElement)
Return the name of the start element
|
static XMLEventReader |
getXMLEventReader(InputStream is)
Get the XML event reader
|
static XMLEventReader |
getXMLEventReader(Source source)
Get the XML event reader
|
static String |
getXSITypeValue(StartElement startElement)
Given a start element, obtain the xsi:type defined
|
static boolean |
hasTextAhead(XMLEventReader xmlEventReader)
Return whether the next event is going to be text
|
static boolean |
matches(EndElement endElement,
String tag)
Match that the end element with the expected tag
|
static boolean |
matches(StartElement startElement,
String tag)
Match that the start element with the expected tag
|
static XMLEvent |
peek(XMLEventReader xmlEventReader)
Peek at the next event
|
static EndElement |
peekNextEndElement(XMLEventReader xmlEventReader)
Peek the next
EndElement |
static StartElement |
peekNextStartElement(XMLEventReader xmlEventReader)
Peek the next
StartElement |
static String |
trim(String str)
Given a string, trim it
|
static void |
validate(EndElement endElement,
String tag)
Validate that the end element has the expected tag
|
static void |
validate(InputStream doc,
InputStream sch) |
static void |
validate(StartElement startElement,
String tag)
Validate that the start element has the expected tag
|
static boolean |
wasWhitespacePeeked(XMLEventReader xmlEventReader,
XMLEvent xmlEvent)
Advances reader if character whitespace encountered
|
public static void validate(InputStream doc, InputStream sch) throws ParsingException
ParsingException
public static void bypassElementBlock(XMLEventReader xmlEventReader, String tag) throws ParsingException
xmlEventReader
is positioned at (has not yet read)
the start element of the block it should bypass.xmlEventReader
- tag
- Tag of the XML element that we need to bypassParsingException
public static XMLEvent bypassElementBlock(XMLEventReader xmlEventReader) throws ParsingException
xmlEventReader
is positioned at (has not yet read)
the start element of the block it should bypass.xmlEventReader
- ParsingException
public static boolean wasWhitespacePeeked(XMLEventReader xmlEventReader, XMLEvent xmlEvent)
xmlEventReader
- xmlEvent
- public static String getAttributeValue(Attribute attribute)
Attribute
, get its trimmed valueattribute
- public static String getAttributeValue(StartElement startElement, String tag)
startElement
- tag
- localpart of the qname of the attributepublic static boolean getBooleanAttributeValue(StartElement startElement, String tag)
startElement
- tag
- localpart of the qname of the attributepublic static boolean getBooleanAttributeValue(StartElement startElement, String tag, boolean defaultValue)
startElement
- tag
- localpart of the qname of the attributepublic static Element getDOMElement(XMLEventReader xmlEventReader) throws ParsingException
XMLEventReader
is in XMLStreamConstants.START_ELEMENT
mode, we parse into a DOM
ElementxmlEventReader
- ParsingException
public static String getElementText(XMLEventReader xmlEventReader) throws ParsingException
xmlEventReader
- ParsingException
public static XMLEventReader getXMLEventReader(InputStream is)
is
- public static XMLEventReader getXMLEventReader(Source source)
source
- public static String getLineColumnNumber(Location location)
Location
, return a formatted string [lineNum,colNum]location
- public static XMLEvent getNextEvent(XMLEventReader xmlEventReader) throws ParsingException
xmlEventReader
- ParsingException
public static StartElement getNextStartElement(XMLEventReader xmlEventReader) throws ParsingException
StartElement
xmlEventReader
- ParsingException
public static EndElement getNextEndElement(XMLEventReader xmlEventReader) throws ParsingException
EndElement
xmlEventReader
- ParsingException
public static String getStartElementName(StartElement startElement)
startElement
- public static String getEndElementName(EndElement endElement)
endElement
- public static String getXSITypeValue(StartElement startElement)
startElement
- RuntimeException
- if xsi:type is missingpublic static boolean hasTextAhead(XMLEventReader xmlEventReader) throws ParsingException
xmlEventReader
- ParsingException
public static boolean matches(StartElement startElement, String tag)
startElement
- tag
- public static boolean matches(EndElement endElement, String tag)
endElement
- tag
- public static XMLEvent peek(XMLEventReader xmlEventReader) throws ParsingException
xmlEventReader
- ParsingException
public static StartElement peekNextStartElement(XMLEventReader xmlEventReader) throws ParsingException
StartElement
xmlEventReader
- ParsingException
public static EndElement peekNextEndElement(XMLEventReader xmlEventReader) throws ParsingException
EndElement
xmlEventReader
- ParsingException
public static final String trim(String str)
str
- {@code
- IllegalArgumentException} if the passed str is nullpublic static void validate(StartElement startElement, String tag)
startElement
- tag
- RuntimeException
- mismatchpublic static void validate(EndElement endElement, String tag)
endElement
- tag
- RuntimeException
- mismatchCopyright © 2019 JBoss by Red Hat. All rights reserved.