public class XMLStreamUtils
extends java.lang.Object
Constructor and Description |
---|
XMLStreamUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
attributeValue(javax.xml.stream.XMLStreamReader reader,
javax.xml.namespace.QName name)
Returns the value of the attribute with the given name.
|
static java.lang.String |
attributeValue(javax.xml.stream.XMLStreamReader reader,
java.lang.String name)
Returns the value of the attribute with the given non-qualified name.
|
static void |
copy(javax.xml.transform.Source source,
javax.xml.stream.XMLEventWriter writer)
Copies the content read from a TrAX
Source to a StAX
XMLEventWriter . |
static void |
copy(javax.xml.transform.Source source,
javax.xml.stream.XMLStreamWriter writer)
Copies the content read from a TrAX
Source to a StAX
XMLStreamWriter . |
static void |
copy(javax.xml.stream.XMLEventReader reader,
javax.xml.transform.Result result)
Copies the content read from a StAX
XMLEventReader to a TrAX
Result . |
static void |
copy(javax.xml.stream.XMLEventReader reader,
javax.xml.stream.util.XMLEventConsumer consumer)
Copies the content read from the specified source stream to the provided
result stream.
|
static void |
copy(javax.xml.stream.XMLEventReader reader,
javax.xml.stream.XMLEventWriter writer)
Copies the content read from the specified source stream to the provided
result stream.
|
static void |
copy(javax.xml.stream.XMLStreamReader reader,
javax.xml.transform.Result result)
Copies the content read from a StAX
XMLStreamReader to a TrAX
Result . |
static void |
copy(javax.xml.stream.XMLStreamReader reader,
javax.xml.stream.XMLStreamWriter writer)
Copies the content read from the specified source stream to the provided
result stream.
|
static void |
copy(javax.xml.stream.XMLStreamReader reader,
javax.xml.stream.XMLStreamWriter writer,
javax.xml.stream.XMLInputFactory factory)
Copies the content read from the specified source stream to the provided
result stream.
|
static void |
copyElement(javax.xml.stream.XMLEventReader reader,
javax.xml.stream.util.XMLEventConsumer consumer)
Copies an element and all its content from the provided event reader, to
the provided event consumer.
|
static void |
copyElementContent(javax.xml.stream.XMLEventReader reader,
javax.xml.stream.util.XMLEventConsumer consumer)
Copies all events within a
StartElement until the matching
EndElement is reached. |
static java.lang.String |
getEventTypeName(int eventType)
Returns the name of the specified stream event constant.
|
static javax.xml.stream.events.StartElement |
mergeAttributes(javax.xml.stream.events.StartElement tag,
java.util.Iterator attrs,
javax.xml.stream.XMLEventFactory factory)
Constructs a new StartElement that merges the attributes and namespaces
found in the specified StartElement, with the provided attributes.
|
static javax.xml.stream.events.StartElement |
nextElement(javax.xml.stream.XMLEventReader reader)
Reads the events from the provided event stream until either a start or
end tag is encountered.
|
static javax.xml.stream.events.StartElement |
nextElement(javax.xml.stream.XMLEventReader reader,
javax.xml.namespace.QName name)
Reads the events from the provided event stream until either a start or
end tag is encountered.
|
static javax.xml.stream.events.XMLEvent |
nextTag(javax.xml.stream.XMLEventReader reader)
Advances the event stream until it encounters a start or end tag, but
does not actaully read the event.
|
static java.lang.String |
readTextElement(javax.xml.stream.XMLEventReader reader,
javax.xml.namespace.QName elemName)
Reads the text content of an element.
|
static void |
requireElement(javax.xml.stream.XMLStreamReader reader,
javax.xml.namespace.QName name)
Static utility method that throws an exception if the supplied reader's
cursor doesn't point to a START_ELEMENT with the given name.
|
static void |
requireStartElement(javax.xml.stream.XMLEventReader reader,
javax.xml.namespace.QName qname)
Utility method that throws an exception if the provided reader is not
positioned before a StartElement event with the specified tag name.
|
static void |
skipElement(javax.xml.stream.XMLEventReader reader)
Skips all events within a single element, including its start and end
tags.
|
static void |
skipElement(javax.xml.stream.XMLStreamReader reader)
Skips the complete content of the element at the specified reader's
cursor.
|
static void |
skipElementContent(javax.xml.stream.XMLEventReader reader)
Skips all events within a
StartElement until the matching
EndElement is reached. |
static void |
skipElementContent(javax.xml.stream.XMLStreamReader reader)
Skips an element's complete content.
|
public static final java.lang.String getEventTypeName(int eventType)
eventType
- The event constant, such as
XMLStreamConstants.START_DOCUMENT
."UNKNOWN"
if the
constant isn't valid.public static final java.lang.String attributeValue(javax.xml.stream.XMLStreamReader reader, java.lang.String name)
reader
- The xml stream readername
- The name of the attribute.null
if the attribute wasn't present.public static final java.lang.String attributeValue(javax.xml.stream.XMLStreamReader reader, javax.xml.namespace.QName name)
reader
- The xml stream readername
- The name of the attribute.null
if the
attribute wasn't present.public static final void skipElement(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
StartElement
event or it will have no effect. After this
method completes, the reader will be positioned before the event
following the end tag (the end tag will have been read).reader
- The event stream to read.javax.xml.stream.XMLStreamException
- If an error occurs reading events.public static final void copyElement(javax.xml.stream.XMLEventReader reader, javax.xml.stream.util.XMLEventConsumer consumer) throws javax.xml.stream.XMLStreamException
reader
- The reader from which to read the events.consumer
- The destination for read events, or null
to
ignore all events.javax.xml.stream.XMLStreamException
- If an error occurs reading or writing the
events.public static final void skipElementContent(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
StartElement
until the matching
EndElement
is reached. This method assumes that the reader
is positioned after the StartElement
event, and when the
method completes, the stream will be positioned before the
EndElement
event, but it will not consume the end tag.reader
- The event stream to read, positioned after the
StartElement
javax.xml.stream.XMLStreamException
- If an error occurs reading events.public static final void copyElementContent(javax.xml.stream.XMLEventReader reader, javax.xml.stream.util.XMLEventConsumer consumer) throws javax.xml.stream.XMLStreamException
StartElement
until the matching
EndElement
is reached. This method assumes that the reader
is positioned after the StartElement
event, and when the
method completes, the stream will be positioned before the
EndElement
event, but it will not consume the end tag.reader
- The event stream to read, positioned after the
StartElement
consumer
- The destination for events read from teh stream, or
null
to ignore the events completely.javax.xml.stream.XMLStreamException
- If an error occurs reading events.public static final void skipElement(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
reader
- An XML stream reader currently in the START_ELEMENT event.javax.xml.stream.XMLStreamException
public static final void skipElementContent(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
START_ELEMENT
has already be passed, and when it terminates,
the stream will be positioned at the END_ELEMENT
.reader
- The stream reader to read.javax.xml.stream.XMLStreamException
- If an error occurs reading the stream.public static final void requireElement(javax.xml.stream.XMLStreamReader reader, javax.xml.namespace.QName name) throws javax.xml.stream.XMLStreamException
reader
- The reader to test.name
- The name of the element to require.javax.xml.stream.XMLStreamException
- If the reader state is an element with the
specified name.public static final void copy(javax.xml.stream.XMLEventReader reader, javax.xml.stream.util.XMLEventConsumer consumer) throws javax.xml.stream.XMLStreamException
XMLEventWriter.add(XMLEventReader)
, and is provided only for
completeness.reader
- The source stream.consumer
- The destination stream.javax.xml.stream.XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(javax.xml.stream.XMLEventReader reader, javax.xml.stream.XMLEventWriter writer) throws javax.xml.stream.XMLStreamException
XMLEventWriter.add(XMLEventReader)
, and is provided only for
completeness.reader
- The source stream.writer
- The destination stream.javax.xml.stream.XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(javax.xml.stream.XMLStreamReader reader, javax.xml.stream.XMLStreamWriter writer) throws javax.xml.stream.XMLStreamException
reader
- The source stream.writer
- The destination stream.javax.xml.stream.XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(javax.xml.stream.XMLStreamReader reader, javax.xml.stream.XMLStreamWriter writer, javax.xml.stream.XMLInputFactory factory) throws javax.xml.stream.XMLStreamException
reader
- The source stream.writer
- The destination stream.factory
- An optional input factory used to create any intermediate
streams.javax.xml.stream.XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(javax.xml.transform.Source source, javax.xml.stream.XMLStreamWriter writer) throws javax.xml.stream.XMLStreamException
Source
to a StAX
XMLStreamWriter
.source
- The content source.writer
- The destination stream.javax.xml.stream.XMLStreamException
- If an error occurs copying the content to the
stream.public static final void copy(javax.xml.transform.Source source, javax.xml.stream.XMLEventWriter writer) throws javax.xml.stream.XMLStreamException
Source
to a StAX
XMLEventWriter
.source
- The content source.writer
- The destination event stream.javax.xml.stream.XMLStreamException
- If an error occurs copying the content to the
event stream.public static final void copy(javax.xml.stream.XMLEventReader reader, javax.xml.transform.Result result) throws javax.xml.stream.XMLStreamException
XMLEventReader
to a TrAX
Result
.reader
- The source event stream.result
- The destination Result
.javax.xml.stream.XMLStreamException
- If an error occurs copying the content to the
result.public static final void copy(javax.xml.stream.XMLStreamReader reader, javax.xml.transform.Result result) throws javax.xml.stream.XMLStreamException
XMLStreamReader
to a TrAX
Result
.reader
- The source stream.result
- The destination Result
.javax.xml.stream.XMLStreamException
- If an error occurs copying the content to the
result.public static final void requireStartElement(javax.xml.stream.XMLEventReader reader, javax.xml.namespace.QName qname) throws javax.xml.stream.XMLStreamException
reader
- The reader to test.qname
- The required name of the start-tag. If null
,
any start tag is accepted.javax.xml.stream.XMLStreamException
- If an error occurs reading from the stream.public static javax.xml.stream.events.StartElement mergeAttributes(javax.xml.stream.events.StartElement tag, java.util.Iterator attrs, javax.xml.stream.XMLEventFactory factory)
tag
- The original StartElementattrs
- An iterator of Atributes to add to the element.public static final java.lang.String readTextElement(javax.xml.stream.XMLEventReader reader, javax.xml.namespace.QName elemName) throws javax.xml.stream.XMLStreamException
reader
- The event stream from which to read the element text.elemName
- The optional name of the element being read. If this
paramter is non- null
then an exception will
be thrown if the element read doesn't have the same name.javax.xml.stream.XMLStreamException
- If an error occurs reading the stream, or if
the read element doesn't match the provided QName.public static final javax.xml.stream.events.XMLEvent nextTag(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
reader
- The reader to peek.peek()
, or null
if the end of the
stream was encountered before any tag event.javax.xml.stream.XMLStreamException
- If an error occurs reading the stream.public static final javax.xml.stream.events.StartElement nextElement(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
null
will be
returned. After returning, the stream will be positioned just before the
returned start element. The start element will not be consumed by this
method.reader
- The event stream from which to read.null
if
an end tag was found first, or the stream ended before a start
element was found.javax.xml.stream.XMLStreamException
- If an error occurs reading the stream.public static final javax.xml.stream.events.StartElement nextElement(javax.xml.stream.XMLEventReader reader, javax.xml.namespace.QName name) throws javax.xml.stream.XMLStreamException
null
will be
returned. After returning, the stream will be positioned just before the
start element. The start element will not be consumed by this method.reader
- The event stream from which to read.name
- The name of the element to read, or null
to
read any start tag.null
if
the encountered start tag didn't match the specified QName, an
end tag was found first, or the stream ended before a start
element was found.javax.xml.stream.XMLStreamException
- If an error occurs reading the stream.