public final class XMLTools
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
avoidUndeclaredNamespaces(java.lang.String xml)
Replaces NS:tag with NS_tag for undeclared namespaces
|
static javax.xml.parsers.DocumentBuilder |
createBuilder()
Creates a new
DocumentBuilder via DocumentBuilderFactory
or logs and throws a RuntimeException . |
static org.w3c.dom.Document |
createDocument()
Calls
DocumentBuilder.newDocument() on a
new builder . |
static java.lang.String |
dumpXML(java.lang.String schemaLocation,
org.w3c.dom.Document doc,
org.w3c.dom.Element r)
Dumps the given OME-XML DOM tree to a string.
|
static java.lang.String |
dumpXML(java.lang.String schemaLocation,
org.w3c.dom.Document doc,
org.w3c.dom.Element r,
boolean includeXMLDeclaration)
Dumps the given OME-XML DOM tree to a string.
|
static java.lang.String |
escapeXML(java.lang.String s)
Escape special characters.
|
static javax.xml.transform.Templates |
getStylesheet(java.lang.String resourcePath,
java.lang.Class<?> sourceClass)
Gets an XSLT template from the given resource location.
|
static java.lang.String |
getXML(org.w3c.dom.Document doc)
Converts the given DOM back to a string.
|
static java.lang.String |
indentXML(java.lang.String xml)
Indents XML to be more readable.
|
static java.lang.String |
indentXML(java.lang.String xml,
boolean preserveCData)
Indents XML to be more readable, avoiding any whitespace
injection into CDATA if the preserveCData flag is set.
|
static java.lang.String |
indentXML(java.lang.String xml,
int spacing)
Indents XML by the given spacing to be more readable.
|
static java.lang.String |
indentXML(java.lang.String xml,
int spacing,
boolean preserveCData)
Indents XML by the given spacing to be more readable, avoiding any
whitespace injection into CDATA if the preserveCData flag is set.
|
static org.w3c.dom.Document |
parseDOM(java.io.File file)
Parses a DOM from the given XML file on disk.
|
static org.w3c.dom.Document |
parseDOM(java.io.InputStream is)
Parses a DOM from the given XML input stream.
|
static org.w3c.dom.Document |
parseDOM(java.lang.String xml)
Parses a DOM from the given XML string.
|
static void |
parseXML(byte[] xml,
org.xml.sax.helpers.DefaultHandler handler)
Parses the XML contained in the given byte array into
using the specified XML handler.
|
static void |
parseXML(java.io.InputStream xml,
org.xml.sax.helpers.DefaultHandler handler)
Parses the XML contained in the given InputStream using the
specified XML handler.
|
static void |
parseXML(RandomAccessInputStream stream,
org.xml.sax.helpers.DefaultHandler handler)
Parses the XML contained in the given input stream into
using the specified XML handler.
|
static java.util.Hashtable<java.lang.String,java.lang.String> |
parseXML(java.lang.String xml)
Parses the given XML string into a list of key/value pairs.
|
static void |
parseXML(java.lang.String xml,
org.xml.sax.helpers.DefaultHandler handler)
Parses the given XML string using the specified XML handler.
|
static java.lang.String |
sanitizeXML(java.lang.String s)
Remove invalid characters from an XML string.
|
static java.lang.String |
transformXML(javax.xml.transform.Source xmlSource,
javax.xml.transform.Templates xslt)
Transforms the given XML data using the specified XSLT stylesheet.
|
static java.lang.String |
transformXML(java.lang.String xml,
javax.xml.transform.Templates xslt)
Transforms the given XML string using the specified XSLT stylesheet.
|
static boolean |
validateXML(java.lang.String xml)
Attempts to validate the given XML string using
Java's XML validation facility.
|
static boolean |
validateXML(java.lang.String xml,
java.lang.String label)
Attempts to validate the given XML string using
Java's XML validation facility.
|
static void |
writeXML(java.io.OutputStream os,
org.w3c.dom.Document doc)
Writes the specified DOM to the given output stream.
|
static void |
writeXML(java.io.OutputStream os,
org.w3c.dom.Document doc,
boolean includeXMLDeclaration)
Writes the specified DOM to the given output stream.
|
public static javax.xml.parsers.DocumentBuilder createBuilder()
DocumentBuilder
via DocumentBuilderFactory
or logs and throws a RuntimeException
.public static org.w3c.dom.Document createDocument()
DocumentBuilder.newDocument()
on a
new builder
.public static org.w3c.dom.Document parseDOM(java.io.File file) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Document parseDOM(java.lang.String xml) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Document parseDOM(java.io.InputStream is) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static java.lang.String getXML(org.w3c.dom.Document doc) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException
public static java.lang.String dumpXML(java.lang.String schemaLocation, org.w3c.dom.Document doc, org.w3c.dom.Element r)
schemaLocation
- if null, no xmlns attribute will be added.public static java.lang.String dumpXML(java.lang.String schemaLocation, org.w3c.dom.Document doc, org.w3c.dom.Element r, boolean includeXMLDeclaration)
schemaLocation
- if null, no xmlns attribute will be added.public static java.lang.String escapeXML(java.lang.String s)
public static java.lang.String sanitizeXML(java.lang.String s)
public static java.lang.String indentXML(java.lang.String xml)
public static java.lang.String indentXML(java.lang.String xml, int spacing)
public static java.lang.String indentXML(java.lang.String xml, boolean preserveCData)
public static java.lang.String indentXML(java.lang.String xml, int spacing, boolean preserveCData)
public static java.util.Hashtable<java.lang.String,java.lang.String> parseXML(java.lang.String xml) throws java.io.IOException
java.io.IOException
public static void parseXML(java.lang.String xml, org.xml.sax.helpers.DefaultHandler handler) throws java.io.IOException
java.io.IOException
public static void parseXML(RandomAccessInputStream stream, org.xml.sax.helpers.DefaultHandler handler) throws java.io.IOException
java.io.IOException
public static void parseXML(byte[] xml, org.xml.sax.helpers.DefaultHandler handler) throws java.io.IOException
java.io.IOException
public static void parseXML(java.io.InputStream xml, org.xml.sax.helpers.DefaultHandler handler) throws java.io.IOException
java.io.IOException
public static void writeXML(java.io.OutputStream os, org.w3c.dom.Document doc) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
public static void writeXML(java.io.OutputStream os, org.w3c.dom.Document doc, boolean includeXMLDeclaration) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
public static javax.xml.transform.Templates getStylesheet(java.lang.String resourcePath, java.lang.Class<?> sourceClass)
public static java.lang.String avoidUndeclaredNamespaces(java.lang.String xml)
public static java.lang.String transformXML(java.lang.String xml, javax.xml.transform.Templates xslt) throws java.io.IOException
java.io.IOException
public static java.lang.String transformXML(javax.xml.transform.Source xmlSource, javax.xml.transform.Templates xslt) throws java.io.IOException
java.io.IOException
public static boolean validateXML(java.lang.String xml)
xml
- The XML string to validate.public static boolean validateXML(java.lang.String xml, java.lang.String label)
xml
- The XML string to validate.label
- String describing the type of XML being validated.Copyright © 2014 Open Microscopy Environment