|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavanet.staxutils.XMLStreamUtils
Static utility methods useful when handling XML Streams.
Constructor Summary | |
XMLStreamUtils()
|
Method Summary | |
static java.lang.String |
attributeValue(XMLStreamReader reader,
QName name)
Returns the value of the attribute with the given name. |
static java.lang.String |
attributeValue(XMLStreamReader reader,
java.lang.String name)
Returns the value of the attribute with the given non-qualified name. |
static void |
copy(Source source,
XMLEventWriter writer)
Copies the content read from a TrAX Source to a StAX
XMLEventWriter . |
static void |
copy(Source source,
XMLStreamWriter writer)
Copies the content read from a TrAX Source to a StAX
XMLStreamWriter . |
static void |
copy(XMLEventReader reader,
Result result)
Copies the content read from a StAX XMLEventReader to a TrAX
Result . |
static void |
copy(XMLEventReader reader,
XMLEventConsumer consumer)
Copies the content read from the specified source stream to the provided result stream. |
static void |
copy(XMLEventReader reader,
XMLEventWriter writer)
Copies the content read from the specified source stream to the provided result stream. |
static void |
copy(XMLStreamReader reader,
Result result)
Copies the content read from a StAX XMLStreamReader to a TrAX
Result . |
static void |
copy(XMLStreamReader reader,
XMLStreamWriter writer)
Copies the content read from the specified source stream to the provided result stream. |
static void |
copy(XMLStreamReader reader,
XMLStreamWriter writer,
XMLInputFactory factory)
Copies the content read from the specified source stream to the provided result stream. |
static void |
copyElement(XMLEventReader reader,
XMLEventConsumer consumer)
Copies an element and all its content from the provided event reader, to the provided event consumer. |
static void |
copyElementContent(XMLEventReader reader,
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 StartElement |
mergeAttributes(StartElement tag,
java.util.Iterator attrs,
XMLEventFactory factory)
Constructs a new StartElement that merges the attributes and namespaces found in the specified StartElement, with the provided attributes. |
static StartElement |
nextElement(XMLEventReader reader)
Reads the events from the provided event stream until either a start or end tag is encountered. |
static StartElement |
nextElement(XMLEventReader reader,
QName name)
Reads the events from the provided event stream until either a start or end tag is encountered. |
static XMLEvent |
nextTag(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(XMLEventReader reader,
QName elemName)
Reads the text content of an element. |
static void |
requireElement(XMLStreamReader reader,
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(XMLEventReader reader,
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(XMLEventReader reader)
Skips all events within a single element, including its start and end tags. |
static void |
skipElement(XMLStreamReader reader)
Skips the complete content of the element at the specified reader's cursor. |
static void |
skipElementContent(XMLEventReader reader)
Skips all events within a StartElement until the matching
EndElement is reached. |
static void |
skipElementContent(XMLStreamReader reader)
Skips an element's complete content. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public XMLStreamUtils()
Method Detail |
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(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(XMLStreamReader reader, QName name)
reader
- The xml stream readername
- The name of the attribute.
null
if the
attribute wasn't present.public static final void skipElement(XMLEventReader reader) throws 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.
XMLStreamException
- If an error occurs reading events.public static final void copyElement(XMLEventReader reader, XMLEventConsumer consumer) throws XMLStreamException
reader
- The reader from which to read the events.consumer
- The destination for read events, or null
to
ignore all events.
XMLStreamException
- If an error occurs reading or writing the
events.public static final void skipElementContent(XMLEventReader reader) throws 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
XMLStreamException
- If an error occurs reading events.public static final void copyElementContent(XMLEventReader reader, XMLEventConsumer consumer) throws 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.
XMLStreamException
- If an error occurs reading events.public static final void skipElement(XMLStreamReader reader) throws XMLStreamException
reader
- An XML stream reader currently in the START_ELEMENT event.
XMLStreamException
public static final void skipElementContent(XMLStreamReader reader) throws 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.
XMLStreamException
- If an error occurs reading the stream.public static final void requireElement(XMLStreamReader reader, QName name) throws XMLStreamException
reader
- The reader to test.name
- The name of the element to require.
XMLStreamException
- If the reader state is an element with the
specified name.public static final void copy(XMLEventReader reader, XMLEventConsumer consumer) throws XMLStreamException
XMLEventWriter.add(XMLEventReader)
, and is provided only for
completeness.
reader
- The source stream.consumer
- The destination stream.
XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(XMLEventReader reader, XMLEventWriter writer) throws XMLStreamException
XMLEventWriter.add(XMLEventReader)
, and is provided only for
completeness.
reader
- The source stream.writer
- The destination stream.
XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException
reader
- The source stream.writer
- The destination stream.
XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(XMLStreamReader reader, XMLStreamWriter writer, XMLInputFactory factory) throws XMLStreamException
reader
- The source stream.writer
- The destination stream.factory
- An optional input factory used to create any intermediate
streams.
XMLStreamException
- If an error occurs copying the stream
contents.public static final void copy(Source source, XMLStreamWriter writer) throws XMLStreamException
Source
to a StAX
XMLStreamWriter
.
source
- The content source.writer
- The destination stream.
XMLStreamException
- If an error occurs copying the content to the
stream.public static final void copy(Source source, XMLEventWriter writer) throws XMLStreamException
Source
to a StAX
XMLEventWriter
.
source
- The content source.writer
- The destination event stream.
XMLStreamException
- If an error occurs copying the content to the
event stream.public static final void copy(XMLEventReader reader, Result result) throws XMLStreamException
XMLEventReader
to a TrAX
Result
.
reader
- The source event stream.result
- The destination Result
.
XMLStreamException
- If an error occurs copying the content to the
result.public static final void copy(XMLStreamReader reader, Result result) throws XMLStreamException
XMLStreamReader
to a TrAX
Result
.
reader
- The source stream.result
- The destination Result
.
XMLStreamException
- If an error occurs copying the content to the
result.public static final void requireStartElement(XMLEventReader reader, QName qname) throws XMLStreamException
reader
- The reader to test.qname
- The required name of the start-tag. If null
,
any start tag is accepted.
XMLStreamException
- If an error occurs reading from the stream.public static StartElement mergeAttributes(StartElement tag, java.util.Iterator attrs, XMLEventFactory factory)
tag
- The original StartElementattrs
- An iterator of Atributes to add to the element.
public static final java.lang.String readTextElement(XMLEventReader reader, QName elemName) throws 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.
XMLStreamException
- If an error occurs reading the stream, or if
the read element doesn't match the provided QName.public static final XMLEvent nextTag(XMLEventReader reader) throws XMLStreamException
reader
- The reader to peek.
peek()
, or null
if the end of the
stream was encountered before any tag event.
XMLStreamException
- If an error occurs reading the stream.public static final StartElement nextElement(XMLEventReader reader) throws 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.
XMLStreamException
- If an error occurs reading the stream.public static final StartElement nextElement(XMLEventReader reader, QName name) throws 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.
XMLStreamException
- If an error occurs reading the stream.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |