public final class XMLTools extends Object
Modifier and Type | Method and Description |
---|---|
static String |
avoidUndeclaredNamespaces(String xml)
Replaces NS:tag with NS_tag for undeclared namespaces
|
static String |
escapeXML(String s)
Escape special characters.
|
static Templates |
getStylesheet(String resourcePath,
Class<?> sourceClass)
Gets an XSLT template from the given resource location.
|
static String |
getXML(Document doc)
Converts the given DOM back to a string.
|
static String |
indentXML(String xml)
Indents XML to be more readable.
|
static String |
indentXML(String xml,
boolean preserveCData)
Indents XML to be more readable, avoiding any whitespace
injection into CDATA if the preserveCData flag is set.
|
static String |
indentXML(String xml,
int spacing)
Indents XML by the given spacing to be more readable.
|
static String |
indentXML(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 Document |
parseDOM(File file)
Parses a DOM from the given XML file on disk.
|
static Document |
parseDOM(InputStream is)
Parses a DOM from the given XML input stream.
|
static Document |
parseDOM(String xml)
Parses a DOM from the given XML string.
|
static void |
parseXML(byte[] xml,
DefaultHandler handler)
Parses the XML contained in the given byte array into
using the specified XML handler.
|
static void |
parseXML(InputStream xml,
DefaultHandler handler)
Parses the XML contained in the given InputStream using the
specified XML handler.
|
static void |
parseXML(RandomAccessInputStream stream,
DefaultHandler handler)
Parses the XML contained in the given input stream into
using the specified XML handler.
|
static Hashtable<String,String> |
parseXML(String xml)
Parses the given XML string into a list of key/value pairs.
|
static void |
parseXML(String xml,
DefaultHandler handler)
Parses the given XML string using the specified XML handler.
|
static String |
sanitizeXML(String s)
Remove invalid characters from an XML string.
|
static String |
transformXML(Source xmlSource,
Templates xslt)
Transforms the given XML data using the specified XSLT stylesheet.
|
static String |
transformXML(String xml,
Templates xslt)
Transforms the given XML string using the specified XSLT stylesheet.
|
static boolean |
validateXML(String xml)
Attempts to validate the given XML string using
Java's XML validation facility.
|
static boolean |
validateXML(String xml,
String label)
Attempts to validate the given XML string using
Java's XML validation facility.
|
public static Document parseDOM(File file) throws ParserConfigurationException, SAXException, IOException
public static Document parseDOM(String xml) throws ParserConfigurationException, SAXException, IOException
public static Document parseDOM(InputStream is) throws ParserConfigurationException, SAXException, IOException
public static String getXML(Document doc) throws TransformerConfigurationException, TransformerException
public static String sanitizeXML(String s)
public static String indentXML(String xml, int spacing)
public static String indentXML(String xml, boolean preserveCData)
public static String indentXML(String xml, int spacing, boolean preserveCData)
public static Hashtable<String,String> parseXML(String xml) throws IOException
IOException
public static void parseXML(String xml, DefaultHandler handler) throws IOException
IOException
public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException
IOException
public static void parseXML(byte[] xml, DefaultHandler handler) throws IOException
IOException
public static void parseXML(InputStream xml, DefaultHandler handler) throws IOException
IOException
public static Templates getStylesheet(String resourcePath, Class<?> sourceClass)
public static String avoidUndeclaredNamespaces(String xml)
public static String transformXML(String xml, Templates xslt) throws IOException
IOException
public static String transformXML(Source xmlSource, Templates xslt) throws IOException
IOException
public static boolean validateXML(String xml)
xml
- The XML string to validate.public static boolean validateXML(String xml, String label)
xml
- The XML string to validate.label
- String describing the type of XML being validated.Copyright © 2014 Open Microscopy Environment