public final class DocumentUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DocumentUtil.PARSER
The parser type.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
clearCache()
Clear the templates cache
|
static org.w3c.dom.Element |
createTextOnlyElement(org.w3c.dom.Document doc,
java.lang.String element_name,
java.lang.String element_value)
Convenience function for creating a text-only element.
|
static JSONObject |
docToJson(org.w3c.dom.Document doc) |
static java.lang.String |
docToString(org.w3c.dom.Document doc)
convert a document to a string.
|
static javax.xml.parsers.DocumentBuilder |
getBuilder()
returns the current builder for this thread
|
static javax.xml.parsers.DocumentBuilder |
getBuilder(DocumentUtil.PARSER parser)
returns the current builder for this thread
|
static java.lang.String |
getNodeText(org.w3c.dom.Document doc,
java.lang.String nodeTag)
get the node text
|
static org.w3c.dom.Document |
loadDocument(java.io.File file)
Load a file and return it as an XML Document object
|
static org.w3c.dom.Document |
loadDocument(java.io.File file,
DocumentUtil.PARSER parser)
Load a file and return it as an XML Document object
|
static org.w3c.dom.Document |
loadEncodedDocument(java.io.File file,
java.lang.String encoding)
Read the encoded file
|
static org.w3c.dom.Document |
makeDocument(java.lang.String xml)
make a document.
|
static org.w3c.dom.Document |
makeDocument(java.lang.String xml,
DocumentUtil.PARSER parser)
make a document.
|
static org.w3c.dom.Document |
newDocument()
Create a new XML document
|
static javax.xml.transform.Transformer |
newTransformer()
New transformer.
|
static javax.xml.transform.Transformer |
newTransformer(java.lang.String xslt)
New XSLT transformer.
|
static java.lang.String |
nodeToString(org.w3c.dom.Node node)
convert a node to a string
|
static void |
normaliseDocument(org.w3c.dom.Node n)
The function normaliseDocument removes superfluous and non-intuitive "#TEXT#" nodes created from a space between
XML elements
sourced from http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-traps-p2.html
|
static void |
writeDocument(org.w3c.dom.Document document,
java.io.File file)
write a document to a file.
|
static void |
writeNode(org.w3c.dom.Node node,
java.io.Writer w)
write a document to a file.
|
static void |
writeNode(org.w3c.dom.Node node,
java.io.Writer w,
int indent)
write a document to a file.
|
@CheckReturnValue
@Nonnull
public static java.lang.String getNodeText(@Nonnull
org.w3c.dom.Document doc,
@Nonnull
java.lang.String nodeTag)
doc - the documentnodeTag - the node@CheckReturnValue
@Nonnull
public static javax.xml.parsers.DocumentBuilder getBuilder()
throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException - a serious problem@CheckReturnValue
@Nonnull
public static javax.xml.parsers.DocumentBuilder getBuilder(@Nonnull
DocumentUtil.PARSER parser)
throws javax.xml.parsers.ParserConfigurationException
parser - the parser to use.javax.xml.parsers.ParserConfigurationException - a serious problem@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document makeDocument(@Nonnull
java.lang.String xml)
throws DocumentException
xml - The XML to parseDocumentException - a serious problem@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document makeDocument(@Nonnull
java.lang.String xml,
@Nonnull
DocumentUtil.PARSER parser)
throws DocumentException
xml - The XML to parseparser - the parser to useDocumentException - a serious problem@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document loadDocument(@Nonnull
java.io.File file)
throws java.lang.Exception
file - the file to read the XML file fromjava.lang.Exception - a serious problem@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document loadDocument(@Nonnull
java.io.File file,
@Nonnull
DocumentUtil.PARSER parser)
throws java.lang.Exception
file - the file to read the XML file fromparser - the parserjava.lang.Exception - a serious problem@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document loadEncodedDocument(@Nonnull
java.io.File file,
@Nonnull
java.lang.String encoding)
throws java.lang.Exception
file - file to be readencoding - what for the encoding isjava.lang.Exception - if file does not existspublic static void writeDocument(@Nonnull
org.w3c.dom.Document document,
@Nonnull
java.io.File file)
throws java.lang.Exception
document - the document to writefile - the file to write to.java.lang.Exception - a serious problempublic static void writeNode(@Nonnull
org.w3c.dom.Node node,
@Nonnull
java.io.Writer w)
throws java.lang.Exception
node - w - java.lang.Exception - a serious problempublic static void writeNode(@Nonnull
org.w3c.dom.Node node,
@Nonnull
java.io.Writer w,
@Nonnegative
int indent)
throws java.lang.Exception
node - w - indent - amount to indentjava.lang.Exception - a serious problempublic static void clearCache()
@CheckReturnValue
@Nonnull
public static javax.xml.transform.Transformer newTransformer(@Nonnull
java.lang.String xslt)
throws javax.xml.transform.TransformerConfigurationException,
java.io.IOException
xslt - the XSLT to transform.javax.xml.transform.TransformerConfigurationExceptionjava.io.IOException - if an IO exception occurs.@CheckReturnValue
@Nonnull
public static javax.xml.transform.Transformer newTransformer()
throws javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerConfigurationException@CheckReturnValue
@Nonnull
public static org.w3c.dom.Document newDocument()
throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException - a serious problem@CheckReturnValue
@Nonnull
public static java.lang.String docToString(@Nonnull
org.w3c.dom.Document doc)
throws java.lang.Exception
doc - The document to convertjava.lang.Exception - a serious problempublic static java.lang.String nodeToString(@Nonnull
org.w3c.dom.Node node)
throws java.lang.Exception
node - the node to convertjava.lang.Exception@CheckReturnValue @Nonnull public static JSONObject docToJson(@Nonnull org.w3c.dom.Document doc) throws java.lang.Exception
java.lang.Exceptionpublic static void normaliseDocument(@Nonnull
org.w3c.dom.Node n)
n - the node to normalize@CheckReturnValue
@Nonnull
public static org.w3c.dom.Element createTextOnlyElement(@Nonnull
org.w3c.dom.Document doc,
@Nonnull
java.lang.String element_name,
@Nonnull
java.lang.String element_value)
doc - the documentelement_name - element_value - stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.