Modifier and Type | Field and Description |
---|---|
static String |
ATTR_SCHEMA_LOCATION |
static String |
ATTR_SCHEMA_LOCATION_LOCAL_PART |
static String |
ATTR_XSI_NAMESPACE |
static Pattern |
XSD_FILE_NAME_PATTERN |
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static FormatVersion |
extractFormatVersion(StartElement startElement)
Extracts the format version from the
xsi:schemaLocation attribute (e.g. |
static String |
extractXSDFileName(StartElement startElement)
Extracts the XSD file name from the
xsi:schemaLocation attribute (e.g. |
static boolean |
reachElementEnd(XMLEventReader reader)
Reads all events from the reader until one more end element than start elements is found.
|
static boolean |
readBooleanAttr(StartElement element,
QName name,
boolean oldValue) |
static boolean |
readCharactersAsBoolean(XMLEventReader reader)
Reads the characters from the next event of the stream a parses them as a
boolean value. |
static double |
readCharactersAsDouble(XMLEventReader reader)
Reads the characters from the next event of the stream a parses them as a
double value. |
static float |
readCharactersAsFloat(XMLEventReader reader)
Reads the characters from the next event of the stream a parses them as a
float value. |
static int |
readCharactersAsInt(XMLEventReader reader)
Reads the characters from the next event of the stream a parses them as an
int value. |
static long |
readCharactersAsLong(XMLEventReader reader)
Reads the characters from the next event of the stream a parses them as an
long value. |
static String |
readCharactersAsString(XMLEventReader reader)
Reads the characters from the next event of the stream.
|
static Color |
readColorAttr(StartElement element,
QName name,
Color oldValue) |
static double |
readDoubleAttr(StartElement element,
QName name,
double oldValue) |
static float |
readFloatAttr(StartElement element,
QName name,
float oldValue) |
static int |
readIntAttr(StartElement element,
QName name,
int oldValue) |
static StartElement |
readRootElement(File file) |
static StartElement |
readRootElement(InputStream stream)
Returns the root element of the XML file that can be read from the specified stream and closes it.
|
static String |
readStringAttr(StartElement element,
QName name,
String oldValue) |
static void |
writeNamespaceAttr(XMLStreamWriter writer,
String namespaceURI)
Adds the
xmlns attribute to the start element which was last written to the specified
writer. |
static void |
writeNamespaceXSDAttr(XMLStreamWriter writer,
String namespaceURI,
String xsdURI)
Adds the attributes
xmlns xmlns:xsi and xsi:schemaLocation
and the according values to the start element which was last written to the specified writer. |
public static final String ATTR_XSI_NAMESPACE
public static final String ATTR_SCHEMA_LOCATION_LOCAL_PART
public static final String ATTR_SCHEMA_LOCATION
public static final Pattern XSD_FILE_NAME_PATTERN
public XMLUtils()
public static boolean reachElementEnd(XMLEventReader reader) throws XMLStreamException
reader
- true
if anything else than ignorable whitespace is found before the next end elementXMLStreamException
public static String readStringAttr(StartElement element, QName name, String oldValue)
public static boolean readBooleanAttr(StartElement element, QName name, boolean oldValue)
public static int readIntAttr(StartElement element, QName name, int oldValue)
public static float readFloatAttr(StartElement element, QName name, float oldValue)
public static double readDoubleAttr(StartElement element, QName name, double oldValue)
public static Color readColorAttr(StartElement element, QName name, Color oldValue)
public static String readCharactersAsString(XMLEventReader reader) throws XMLStreamException
reader
- the stream to read the next element fromXMLStreamException
public static boolean readCharactersAsBoolean(XMLEventReader reader) throws XMLStreamException
boolean
value.reader
- the stream to read the next element fromXMLStreamException
public static int readCharactersAsInt(XMLEventReader reader) throws XMLStreamException
int
value.reader
- the stream to read the next element fromXMLStreamException
public static long readCharactersAsLong(XMLEventReader reader) throws XMLStreamException
long
value.reader
- the stream to read the next element fromXMLStreamException
public static float readCharactersAsFloat(XMLEventReader reader) throws XMLStreamException
float
value.reader
- the stream to read the next element fromXMLStreamException
public static double readCharactersAsDouble(XMLEventReader reader) throws XMLStreamException
double
value.reader
- the stream to read the next element fromXMLStreamException
public static StartElement readRootElement(InputStream stream) throws IOException, XMLStreamException
stream
- the stream to read from (closed after the execution of this method)IOException
- if the stream cannot be closedXMLStreamException
- if the XML format is invalidpublic static StartElement readRootElement(File file) throws IOException, XMLStreamException
IOException
XMLStreamException
public static void writeNamespaceAttr(XMLStreamWriter writer, String namespaceURI) throws 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)XMLStreamException
public static void writeNamespaceXSDAttr(XMLStreamWriter writer, String namespaceURI, String xsdURI) throws 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 elementXMLStreamException
public static String extractXSDFileName(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(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 malformed