public class XMLUtils extends java.lang.Object
| Modifier and Type | Field and Description | 
|---|---|
| static java.lang.String | ATTR_SCHEMA_LOCATION | 
| static java.lang.String | ATTR_SCHEMA_LOCATION_LOCAL_PART | 
| static java.lang.String | ATTR_XSI_NAMESPACE | 
| static java.lang.String | QNAME_SEPARATOR | 
| static java.util.regex.Pattern | XSD_FILE_NAME_PATTERN | 
| Constructor and Description | 
|---|
| XMLUtils() | 
| Modifier and Type | Method and Description | 
|---|---|
| static FormatVersion | extractFormatVersion(javax.xml.stream.events.StartElement startElement)Extracts the format version from the  xsi:schemaLocationattribute (e.g. | 
| static java.lang.String | extractXSDFileName(javax.xml.stream.events.StartElement startElement)Extracts the XSD file name from the  xsi:schemaLocationattribute (e.g. | 
| static boolean | isCharacterType(int type) | 
| static boolean | reachElementEnd(javax.xml.stream.XMLEventReader reader)Reads all events from the  XMLEventReaderuntil one more end element than start elements is found. | 
| static boolean | reachElementEnd(javax.xml.stream.XMLStreamReader reader)Reads all events from the  XMLStreamReaderuntil one more end element than start elements is found. | 
| static boolean | readBooleanAttr(javax.xml.stream.events.StartElement element,
               javax.xml.namespace.QName name,
               boolean oldValue) | 
| static boolean | readCharactersAsBoolean(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReadera parses them as abooleanvalue. | 
| static boolean | readCharactersAsBoolean(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReadera parses them as abooleanvalue. | 
| static double | readCharactersAsDouble(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReadera parses them as adoublevalue. | 
| static double | readCharactersAsDouble(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReadera parses them as adoublevalue. | 
| static float | readCharactersAsFloat(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReadera parses them as afloatvalue. | 
| static float | readCharactersAsFloat(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReadera parses them as afloatvalue. | 
| static int | readCharactersAsInt(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReadera parses them as anintvalue. | 
| static int | readCharactersAsInt(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReadera parses them as aintvalue. | 
| static long | readCharactersAsLong(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReadera parses them as anlongvalue. | 
| static long | readCharactersAsLong(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReadera parses them as alongvalue. | 
| static java.lang.String | readCharactersAsString(javax.xml.stream.XMLEventReader reader)Reads the characters from the next event of the  XMLEventReader. | 
| static java.lang.String | readCharactersAsString(javax.xml.stream.XMLStreamReader reader)Reads the characters from the next event of the  XMLStreamReader. | 
| static java.awt.Color | readColorAttr(javax.xml.stream.events.StartElement element,
             javax.xml.namespace.QName name,
             java.awt.Color oldValue) | 
| static double | readDoubleAttr(javax.xml.stream.events.StartElement element,
              javax.xml.namespace.QName name,
              double oldValue) | 
| static float | readFloatAttr(javax.xml.stream.events.StartElement element,
             javax.xml.namespace.QName name,
             float oldValue) | 
| static int | readIntAttr(javax.xml.stream.events.StartElement element,
           javax.xml.namespace.QName name,
           int oldValue) | 
| static javax.xml.stream.events.StartElement | readRootElement(java.io.File file) | 
| static javax.xml.stream.events.StartElement | readRootElement(java.io.InputStream stream)Returns the root element of the XML file that can be read from the specified stream and closes it. | 
| static java.lang.String | readStringAttr(javax.xml.stream.events.StartElement element,
              javax.xml.namespace.QName name,
              java.lang.String oldValue) | 
| static void | writeAttribute(javax.xml.stream.XMLStreamWriter writer,
              javax.xml.namespace.QName name,
              java.lang.String value)Writes an attribute with a name defined by a  QNameto anXMLStreamWriter. | 
| static void | writeNamespaceAttr(javax.xml.stream.XMLStreamWriter writer,
                  java.lang.String namespaceURI)Adds the  xmlnsattribute to the start element which was last written to the specified 
 writer. | 
| static void | writeNamespaceXSDAttr(javax.xml.stream.XMLStreamWriter writer,
                     java.lang.String namespaceURI,
                     java.lang.String xsdURI)Adds the attributes  xmlnsxmlns:xsiandxsi:schemaLocationand the according values to the start element which was last written to the specified writer. | 
| static void | writeStartElement(javax.xml.stream.XMLStreamWriter writer,
                 javax.xml.namespace.QName name)Writes a start element defined by a  QNameto anXMLStreamWriter. | 
public static final java.lang.String QNAME_SEPARATOR
public static final java.lang.String ATTR_XSI_NAMESPACE
public static final java.lang.String ATTR_SCHEMA_LOCATION_LOCAL_PART
public static final java.lang.String ATTR_SCHEMA_LOCATION
public static final java.util.regex.Pattern XSD_FILE_NAME_PATTERN
public XMLUtils()
public static boolean reachElementEnd(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader until one more end element than start elements is found.reader - the reader to read the events fromtrue if anything else than ignorable whitespace is found before the next end elementjavax.xml.stream.XMLStreamExceptionpublic static boolean reachElementEnd(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader until one more end element than start elements is found.reader - the reader to read the events fromtrue if anything else than ignorable whitespace is found before the next end elementjavax.xml.stream.XMLStreamExceptionpublic static java.lang.String readStringAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, java.lang.String oldValue)
public static boolean readBooleanAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, boolean oldValue)
public static int readIntAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, int oldValue)
public static float readFloatAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, float oldValue)
public static double readDoubleAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, double oldValue)
public static java.awt.Color readColorAttr(javax.xml.stream.events.StartElement element, javax.xml.namespace.QName name, java.awt.Color oldValue)
public static boolean isCharacterType(int type)
public static java.lang.String readCharactersAsString(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader. If the next event is not a character event an empty 
 string ("") is returned. All encountered comment events will be skipped.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerpublic static java.lang.String readCharactersAsString(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader. If the next event is not a character event an empty 
 string ("") is returned. All encountered comment events will be skipped.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerpublic static boolean readCharactersAsBoolean(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader a parses them as a boolean value.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerpublic static boolean readCharactersAsBoolean(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader a parses them as a boolean value.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerpublic static int readCharactersAsInt(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader a parses them as an int value.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no int can be parsed from the current characterspublic static int readCharactersAsInt(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader a parses them as a int value.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no int can be parsed from the current characterspublic static long readCharactersAsLong(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader a parses them as an long value.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no long can be parsed from the current characterspublic static long readCharactersAsLong(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader a parses them as a long value.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no long can be parsed from the current characterspublic static float readCharactersAsFloat(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader a parses them as a float value.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no float can be parsed from the current characterspublic static float readCharactersAsFloat(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader a parses them as a float value.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no float can be parsed from the current characterspublic static double readCharactersAsDouble(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
XMLEventReader a parses them as a double value.
 
 After calling this method the next element returned by reader will be the first non-character event after the 
 iterator's position before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no double can be parsed from the current characterspublic static double readCharactersAsDouble(javax.xml.stream.XMLStreamReader reader) throws javax.xml.stream.XMLStreamException
XMLStreamReader a parses them as a double value.
 
 After calling this method reader will be positioned at the first non-character event after the cursor's position 
 before calling this method.
reader - the reader to read the next element fromjavax.xml.stream.XMLStreamException - if thrown by readerjava.lang.NumberFormatException - if no double can be parsed from the current characterspublic static javax.xml.stream.events.StartElement readRootElement(java.io.InputStream stream) throws java.io.IOException, javax.xml.stream.XMLStreamException
stream - the stream to read from (closed after the execution of this method)java.io.IOException - if the stream cannot be closedjavax.xml.stream.XMLStreamException - if the XML format is invalidpublic static javax.xml.stream.events.StartElement readRootElement(java.io.File file) throws java.io.IOException, javax.xml.stream.XMLStreamException
java.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic static void writeNamespaceAttr(javax.xml.stream.XMLStreamWriter writer, java.lang.String namespaceURI) throws javax.xml.stream.XMLStreamException
xmlns attribute to the start element which was last written to the specified 
 writer.writer - the writer which generates the XML outputnamespaceURI - the URI of the namespace (e.g. http://www.w3.org/1999/xhtml)javax.xml.stream.XMLStreamException - if fired by writerpublic static void writeNamespaceXSDAttr(javax.xml.stream.XMLStreamWriter writer, java.lang.String namespaceURI, java.lang.String xsdURI) throws javax.xml.stream.XMLStreamException
xmlns xmlns:xsi and xsi:schemaLocation 
 and the according values to the start element which was last written to the specified writer.writer - the writer which generates the XML outputnamespaceURI - the URI of the namespace (e.g. http://www.w3.org/1999/xhtml)xsdURI - the URI which specifies the XML schema (xsd) which defines the XML code under the
        last start elementjavax.xml.stream.XMLStreamException - if fired by writerpublic static java.lang.String extractXSDFileName(javax.xml.stream.events.StartElement startElement) throws InvalidXSDPathException
xsi:schemaLocation attribute (e.g. 1.1 from 
 http://bioinfweb.info/xmlns/xtg http://bioinfweb.info/xmlns/xtg/1.1.xsd).startElement - the element containing the xsi:schemaLocation attributenull if startElement has no 
         xsi:schemaLocation attributeInvalidXSDPathException - if the path to the XSD file in malformedpublic static FormatVersion extractFormatVersion(javax.xml.stream.events.StartElement startElement) throws InvalidXSDPathException
xsi:schemaLocation attribute (e.g. 1.1 from 
 http://bioinfweb.info/xmlns/xtg http://bioinfweb.info/xmlns/xtg/1.1.xsd). The name of the XSD
 file has to consist of the format version where major and minor version are separated by a dot.startElement - the element containing the xsi:schemaLocation attributenull if startElement has no 
         xsi:schemaLocation attributeInvalidXSDPathException - if the path to the XSD file in malformedpublic static void writeStartElement(javax.xml.stream.XMLStreamWriter writer, javax.xml.namespace.QName name) throws javax.xml.stream.XMLStreamException
QName to an XMLStreamWriter.writer - the writer to write the start tagname - the name of the tagjavax.xml.stream.XMLStreamException - thrown by the specified writerpublic static void writeAttribute(javax.xml.stream.XMLStreamWriter writer, javax.xml.namespace.QName name, java.lang.String value) throws javax.xml.stream.XMLStreamException, java.lang.IllegalStateException
QName to an XMLStreamWriter.writer - the writer to write the start tagname - the name of the tagvalue - the value of the attributejava.lang.IllegalStateException - if the current state does not allow attribute writingjavax.xml.stream.XMLStreamException - if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces 
         has not been set to true