| java.lang.Object javanet.staxutils.XMLStreamUtils
XMLStreamUtils | public class XMLStreamUtils (Code) | | Static utility methods useful when handling XML Streams.
author: Christian Niles version: $Revision: 1.8 $ |
Method Summary | |
final public static String | attributeValue(XMLStreamReader reader, String name) Returns the value of the attribute with the given non-qualified name.
Parameters: reader - The xml stream reader Parameters: name - The name of the attribute. | final public static String | attributeValue(XMLStreamReader reader, QName name) Returns the value of the attribute with the given name.
Parameters: reader - The xml stream reader Parameters: name - The name of the attribute. | final public static void | copy(XMLEventReader reader, XMLEventConsumer consumer) Copies the content read from the specified source stream to the provided
result stream. | final public static void | copy(XMLEventReader reader, XMLEventWriter writer) Copies the content read from the specified source stream to the provided
result stream. | final public static void | copy(XMLStreamReader reader, XMLStreamWriter writer) Copies the content read from the specified source stream to the provided
result stream. | final public static void | copy(XMLStreamReader reader, XMLStreamWriter writer, XMLInputFactory factory) Copies the content read from the specified source stream to the provided
result stream. | final public static void | copy(Source source, XMLStreamWriter writer) Copies the content read from a TrAX
Source to a StAX
XMLStreamWriter . | final public static void | copy(Source source, XMLEventWriter writer) Copies the content read from a TrAX
Source to a StAX
XMLEventWriter . | final public static void | copy(XMLEventReader reader, Result result) Copies the content read from a StAX
XMLEventReader to a TrAX
Result . | final public static void | copy(XMLStreamReader reader, Result result) Copies the content read from a StAX
XMLStreamReader to a TrAX
Result . | final public static void | copyElement(XMLEventReader reader, XMLEventConsumer consumer) Copies an element and all its content from the provided event reader, to
the provided event consumer. | final public static void | copyElementContent(XMLEventReader reader, XMLEventConsumer consumer) Copies all events within a StartElement until the matching
EndElement is reached. | final public static String | getEventTypeName(int eventType) Returns the name of the specified stream event constant.
Parameters: eventType - The event constant, such asXMLStreamConstants.START_DOCUMENT. | public static StartElement | mergeAttributes(StartElement tag, Iterator attrs, XMLEventFactory factory) Constructs a new StartElement that merges the attributes and namespaces
found in the specified StartElement, with the provided attributes. | final public static StartElement | nextElement(XMLEventReader reader) Reads the events from the provided event stream until either a start or
end tag is encountered. | final public static StartElement | nextElement(XMLEventReader reader, QName name) Reads the events from the provided event stream until either a start or
end tag is encountered. | final public static XMLEvent | nextTag(XMLEventReader reader) Advances the event stream until it encounters a start or end tag, but
does not actaully read the event.
Parameters: reader - The reader to peek. | final public static String | readTextElement(XMLEventReader reader, QName elemName) Reads the text content of an element. | final public 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. | final public 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.
Parameters: reader - The reader to test. Parameters: qname - The required name of the start-tag. | final public static void | skipElement(XMLEventReader reader) Skips all events within a single element, including its start and end
tags. | final public static void | skipElement(XMLStreamReader reader) Skips the complete content of the element at the specified reader's
cursor. | final public static void | skipElementContent(XMLEventReader reader) Skips all events within a StartElement until the matching
EndElement is reached. | final public static void | skipElementContent(XMLStreamReader reader) Skips an element's complete content. |
attributeValue | final public static String attributeValue(XMLStreamReader reader, String name)(Code) | | Returns the value of the attribute with the given non-qualified name.
Parameters: reader - The xml stream reader Parameters: name - The name of the attribute. The value of the unqualified attribute, or null if the attribute wasn't present. |
attributeValue | final public static String attributeValue(XMLStreamReader reader, QName name)(Code) | | Returns the value of the attribute with the given name.
Parameters: reader - The xml stream reader Parameters: name - The name of the attribute. The value of the attribute, or null if theattribute wasn't present. |
copy | final public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException(Code) | | Copies the content read from the specified source stream to the provided
result stream.
Parameters: reader - The source stream. Parameters: writer - The destination stream. throws: XMLStreamException - If an error occurs copying the streamcontents. |
copy | final public static void copy(XMLStreamReader reader, XMLStreamWriter writer, XMLInputFactory factory) throws XMLStreamException(Code) | | Copies the content read from the specified source stream to the provided
result stream.
Parameters: reader - The source stream. Parameters: writer - The destination stream. Parameters: factory - An optional input factory used to create any intermediatestreams. throws: XMLStreamException - If an error occurs copying the streamcontents. |
copyElement | final public static void copyElement(XMLEventReader reader, XMLEventConsumer consumer) throws XMLStreamException(Code) | | Copies an element and all its content from the provided event reader, to
the provided event consumer. The event reader must be positioned before a
start element event, or this method has no effect.
Parameters: reader - The reader from which to read the events. Parameters: consumer - The destination for read events, or null toignore all events. throws: XMLStreamException - If an error occurs reading or writing theevents. |
copyElementContent | final public static void copyElementContent(XMLEventReader reader, XMLEventConsumer consumer) throws XMLStreamException(Code) | | Copies all events within a 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.
Parameters: reader - The event stream to read, positioned after theStartElement Parameters: consumer - The destination for events read from teh stream, ornull to ignore the events completely. throws: XMLStreamException - If an error occurs reading events. |
getEventTypeName | final public static String getEventTypeName(int eventType)(Code) | | Returns the name of the specified stream event constant.
Parameters: eventType - The event constant, such asXMLStreamConstants.START_DOCUMENT. The name of the specified event, or "UNKNOWN" if theconstant isn't valid. |
mergeAttributes | public static StartElement mergeAttributes(StartElement tag, Iterator attrs, XMLEventFactory factory)(Code) | | Constructs a new StartElement that merges the attributes and namespaces
found in the specified StartElement, with the provided attributes. The
returned StartElement will contain all the attributes and namespaces of
the original, plus those defined in the map.
Parameters: tag - The original StartElement Parameters: attrs - An iterator of Atributes to add to the element. A new StartElement that contains all the original attributes andnamespaces, plus the provided attributes. |
nextElement | final public static StartElement nextElement(XMLEventReader reader) throws XMLStreamException(Code) | | Reads the events from the provided event stream until either a start or
end tag is encountered. In the former case, the start tag will be
returned, but if an end tag is encountered, 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.
Parameters: reader - The event stream from which to read. The StartElement read from the stream, or null ifan end tag was found first, or the stream ended before a startelement was found. throws: XMLStreamException - If an error occurs reading the stream. |
nextElement | final public static StartElement nextElement(XMLEventReader reader, QName name) throws XMLStreamException(Code) | | Reads the events from the provided event stream until either a start or
end tag is encountered. In the former case, the start tag will be
returned if it matches the specified QName, but if it doesn't match, an
end tag is encountered, or the stream ends, 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.
Parameters: reader - The event stream from which to read. Parameters: name - The name of the element to read, or null toread any start tag. The StartElement read from the stream, or null ifthe encountered start tag didn't match the specified QName, anend tag was found first, or the stream ended before a startelement was found. throws: XMLStreamException - If an error occurs reading the stream. |
nextTag | final public static XMLEvent nextTag(XMLEventReader reader) throws XMLStreamException(Code) | | Advances the event stream until it encounters a start or end tag, but
does not actaully read the event.
Parameters: reader - The reader to peek. The next StartElement or EndElement event, retrieved usingpeek() , or null if the end of thestream was encountered before any tag event. throws: XMLStreamException - If an error occurs reading the stream. |
readTextElement | final public static String readTextElement(XMLEventReader reader, QName elemName) throws XMLStreamException(Code) | | Reads the text content of an element. The reader should be positioned in
front of a StartElement event, and will be read up to and including the
end element tag.
Parameters: reader - The event stream from which to read the element text. Parameters: elemName - The optional name of the element being read. If thisparamter is non- null then an exception willbe thrown if the element read doesn't have the same name. The text read from the element. throws: XMLStreamException - If an error occurs reading the stream, or ifthe read element doesn't match the provided QName. |
requireElement | final public static void requireElement(XMLStreamReader reader, QName name) throws XMLStreamException(Code) | | Static utility method that throws an exception if the supplied reader's
cursor doesn't point to a START_ELEMENT with the given name.
Parameters: reader - The reader to test. Parameters: name - The name of the element to require. throws: XMLStreamException - If the reader state is an element with thespecified name. |
requireStartElement | final public static void requireStartElement(XMLEventReader reader, QName qname) throws XMLStreamException(Code) | | Utility method that throws an exception if the provided reader is not
positioned before a StartElement event with the specified tag name.
Parameters: reader - The reader to test. Parameters: qname - The required name of the start-tag. If null ,any start tag is accepted. throws: XMLStreamException - If an error occurs reading from the stream. |
skipElement | final public static void skipElement(XMLEventReader reader) throws XMLStreamException(Code) | | Skips all events within a single element, including its start and end
tags. The provided reader must be positioned directly in front of a
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).
Parameters: reader - The event stream to read. throws: XMLStreamException - If an error occurs reading events. |
skipElement | final public static void skipElement(XMLStreamReader reader) throws XMLStreamException(Code) | | Skips the complete content of the element at the specified reader's
cursor. The reader's current event type must be START_ELEMENT, otherwise
this method will have no effect. Upon completion, the reader's cursor
will be at the END_ELEMENT event for the skipped element.
Parameters: reader - An XML stream reader currently in the START_ELEMENT event. |
skipElementContent | final public static void skipElementContent(XMLEventReader reader) throws XMLStreamException(Code) | | Skips all events within a 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.
Parameters: reader - The event stream to read, positioned after theStartElement throws: XMLStreamException - If an error occurs reading events. |
skipElementContent | final public static void skipElementContent(XMLStreamReader reader) throws XMLStreamException(Code) | | Skips an element's complete content. This method assumes that the
START_ELEMENT has already be passed, and when it terminates,
the stream will be positioned at the END_ELEMENT .
Parameters: reader - The stream reader to read. throws: XMLStreamException - If an error occurs reading the stream. |
|
|