public final class UtilXml extends Object
Modifier and Type | Class and Description |
---|---|
static class |
UtilXml.LocalErrorHandler
Local error handler for entity resolver to DocumentBuilder parser.
|
static class |
UtilXml.LocalResolver
Local entity resolver to handle J2EE DTDs.
|
Modifier and Type | Method and Description |
---|---|
static Element |
addChildElement(Element element,
String childElementName,
Document document)
Creates a child element with the given name and appends it to the element child node list.
|
static Element |
addChildElementCDATAValue(Element element,
String childElementName,
String childElementValue,
Document document)
Creates a child element with the given name and appends it to the element child node list.
|
static Element |
addChildElementNSElement(Element element,
String childElementName,
Document document,
String nameSpaceUrl)
Creates a child element with the given namespace supportive name and appends it to the element child node list.
|
static Element |
addChildElementNSValue(Element element,
String childElementName,
String childElementValue,
Document document,
String nameSpaceUrl)
Creates a child element with the given namespace supportive name and appends it to the element child node list.
|
static Element |
addChildElementValue(Element element,
String childElementName,
String childElementValue,
Document document)
Creates a child element with the given name and appends it to the element child node list.
|
static boolean |
checkBoolean(String str) |
static boolean |
checkBoolean(String str,
boolean defaultValue) |
static String |
checkEmpty(String string) |
static String |
checkEmpty(String string1,
String string2) |
static String |
checkEmpty(String string1,
String string2,
String string3) |
static String |
childElementAttribute(Element element,
String childElementName,
String attributeName,
String defaultValue)
Return a named attribute of a named child node or a default if null.
|
static List<? extends Element> |
childElementList(DocumentFragment fragment)
Return a List of Element objects that are children of the given DocumentFragment
|
static List<? extends Element> |
childElementList(Element element)
Return a List of Element objects that are children of the given element
|
static List<? extends Element> |
childElementList(Element element,
Set<String> childElementNames)
Return a List of Element objects that have the given name and are
immediate children of the given element; if name is null, all child
elements will be included.
|
static List<? extends Element> |
childElementList(Element element,
String... childElementNames)
Return a List of Element objects that have the given name and are
immediate children of the given element; if name is null, all child
elements will be included.
|
static List<? extends Element> |
childElementList(Element element,
String childElementName)
Return a List of Element objects that have the given name and are
immediate children of the given element; if name is null, all child
elements will be included.
|
static String |
childElementValue(Element element,
String childElementName)
Return the text (node value) contained by the named child node.
|
static String |
childElementValue(Element element,
String childElementName,
String defaultValue)
Return the text (node value) contained by the named child node or a default value if null.
|
static List<? extends Node> |
childNodeList(Node node)
Return a List of Node objects that have the given name and are immediate children of the given element;
if name is null, all child elements will be included.
|
static LSOutput |
createLSOutput(DOMImplementationLS impl,
OutputStream os,
String encoding)
Returns a
LSOutput instance. |
static LSSerializer |
createLSSerializer(DOMImplementationLS impl,
boolean includeXmlDeclaration,
boolean enablePrettyPrint)
Returns a
LSSerializer instance. |
static Transformer |
createOutputTransformer(String encoding,
boolean omitXmlDeclaration,
boolean indent,
int indentAmount)
Creates a JAXP TrAX Transformer suitable for pretty-printing an
XML document.
|
static String |
elementAttribute(Element element,
String attrName,
String defaultValue) |
static String |
elementValue(Element element)
Return the text (node value) of the first node under this, works best if normalized.
|
static Element |
firstChildElement(Element element)
Return the first child Element
returns the first element.
|
static Element |
firstChildElement(Element element,
Set<String> childElementNames)
Return the first child Element
returns the first element.
|
static Element |
firstChildElement(Element element,
String... childElementNames)
Return the first child Element
returns the first element.
|
static Element |
firstChildElement(Element element,
String childElementName)
Return the first child Element with the given name; if name is null
returns the first element.
|
static Element |
firstChildElement(Element element,
String childElementName,
String attrName,
String attrValue)
Return the first child Element with the given name; if name is null
returns the first element.
|
static Object |
fromXml(InputStream input)
Deserialize an object from an
InputStream . |
static Object |
fromXml(Reader reader)
Deserialize an object from a
Reader . |
static Object |
fromXml(String str)
Deserialize an object from a
String . |
static String |
getAttributeValueIgnorePrefix(Element element,
String attributeName)
get attribute value ignoring prefix in attribute name
|
static DOMImplementationLS |
getDomLsImplementation()
Returns a
DOMImplementationLS instance. |
static String |
getNodeNameIgnorePrefix(Node node)
get node name without any prefix
|
static String |
getTagNameIgnorePrefix(Element element)
get tag name without any prefix
|
static Document |
makeEmptyXmlDocument() |
static Document |
makeEmptyXmlDocument(String rootElementName) |
static String |
nodeNameToJavaName(String nodeName,
boolean capitalizeFirst) |
static String |
nodeValue(Node node)
Return the text (node value) of the first node under this
|
static Document |
readXmlDocument(InputStream is,
boolean validate,
String docDescription) |
static Document |
readXmlDocument(InputStream is,
boolean validate,
String docDescription,
boolean withPosition) |
static Document |
readXmlDocument(InputStream is,
String docDescription) |
static Document |
readXmlDocument(InputStream is,
String docDescription,
boolean withPosition) |
static Document |
readXmlDocument(String content) |
static Document |
readXmlDocument(String content,
boolean validate) |
static Document |
readXmlDocument(String content,
boolean validate,
boolean withPosition) |
static Document |
readXmlDocument(URL url) |
static Document |
readXmlDocument(URL url,
boolean validate) |
static Document |
readXmlDocument(URL url,
boolean validate,
boolean withPosition) |
static String |
toXml(Object obj)
Serialize an object to an XML
String . |
static void |
toXml(Object obj,
OutputStream output)
Serialize an object to an
OutputStream . |
static void |
toXml(Object obj,
Writer writer)
Serialize an object to a
Writer . |
static void |
transformDomDocument(Transformer transformer,
Node node,
OutputStream os)
Serializes a DOM
Node to an OutputStream
using JAXP TrAX. |
static String |
writeXmlDocument(Node node) |
static void |
writeXmlDocument(Node node,
OutputStream os,
String encoding,
boolean omitXmlDeclaration,
boolean indent,
int indentAmount)
Serializes a DOM
Node to an OutputStream
using JAXP TrAX. |
static void |
writeXmlDocument(OutputStream os,
Node node) |
static void |
writeXmlDocument(OutputStream os,
Node node,
String encoding,
boolean includeXmlDeclaration,
boolean enablePrettyPrint)
Serializes a DOM Node to an
OutputStream using DOM 3. |
static void |
writeXmlDocument(String filename,
Node node) |
public static final String module
public static DOMImplementationLS getDomLsImplementation() throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException
DOMImplementationLS
instance.DOMImplementationLS
instanceClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException
public static LSOutput createLSOutput(DOMImplementationLS impl, OutputStream os, String encoding)
LSOutput
instance.impl
- A DOMImplementationLS
instanceos
- Optional OutputStream
instanceencoding
- Optional character encoding, default is UTF-8LSOutput
instancepublic static LSSerializer createLSSerializer(DOMImplementationLS impl, boolean includeXmlDeclaration, boolean enablePrettyPrint)
LSSerializer
instance.impl
- A DOMImplementationLS
instanceincludeXmlDeclaration
- If set to true
,
the xml declaration will be included in the outputenablePrettyPrint
- If set to true
, the
output will be formatted in human-readable form. If set to
false
, the entire document will consist of a single line.LSSerializer
instancepublic static void writeXmlDocument(OutputStream os, Node node, String encoding, boolean includeXmlDeclaration, boolean enablePrettyPrint) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException
OutputStream
using DOM 3.os
- The OutputStream
instance to write tonode
- The DOM Node
object to be serializedencoding
- Optional character encodingincludeXmlDeclaration
- If set to true
,
the xml declaration will be included in the outputenablePrettyPrint
- If set to true
, the
output will be formatted in human-readable form. If set to
false
, the entire document will consist of a single line.ClassCastException
ClassNotFoundException
InstantiationException
IllegalAccessException
public static Transformer createOutputTransformer(String encoding, boolean omitXmlDeclaration, boolean indent, int indentAmount) throws TransformerConfigurationException
org.apache.xml.serialize.OutputFormat
class.encoding
- Optional encoding, defaults to UTF-8omitXmlDeclaration
- If true
the xml declaration
will be omitted from the outputindent
- If true
, the output will be indentedindentAmount
- If indent
is true
,
the number of spaces to indent. Default is 4.Transformer
instanceTransformerConfigurationException
public static void transformDomDocument(Transformer transformer, Node node, OutputStream os) throws TransformerException
Node
to an OutputStream
using JAXP TrAX.transformer
- A Transformer
instancenode
- The Node
to serializeos
- The OutputStream
to serialize toTransformerException
public static void writeXmlDocument(Node node, OutputStream os, String encoding, boolean omitXmlDeclaration, boolean indent, int indentAmount) throws TransformerException
Node
to an OutputStream
using JAXP TrAX.node
- The Node
to serializeos
- The OutputStream
to serialize toencoding
- Optional encoding, defaults to UTF-8omitXmlDeclaration
- If true
the xml declaration
will be omitted from the outputindent
- If true
, the output will be indentedindentAmount
- If indent
is true
,
the number of spaces to indent. Default is 4.TransformerException
public static Object fromXml(InputStream input)
InputStream
.input
- The InputStream
Object
public static Object fromXml(Reader reader)
Reader
.reader
- The Reader
Object
public static Object fromXml(String str)
String
.str
- The String
Object
public static String toXml(Object obj)
String
.obj
- The object to serializeString
public static void toXml(Object obj, OutputStream output)
OutputStream
.obj
- The object to serializeoutput
- The OutputStream
public static void toXml(Object obj, Writer writer)
Writer
.obj
- The object to serializewriter
- The Writer
public static String writeXmlDocument(Node node) throws IOException
IOException
public static void writeXmlDocument(String filename, Node node) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static void writeXmlDocument(OutputStream os, Node node) throws IOException
IOException
public static Document readXmlDocument(String content) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(String content, boolean validate) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(String content, boolean validate, boolean withPosition) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(URL url) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(URL url, boolean validate) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(URL url, boolean validate, boolean withPosition) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(InputStream is, String docDescription) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(InputStream is, String docDescription, boolean withPosition) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(InputStream is, boolean validate, String docDescription) throws SAXException, ParserConfigurationException, IOException
public static Document readXmlDocument(InputStream is, boolean validate, String docDescription, boolean withPosition) throws SAXException, ParserConfigurationException, IOException
public static Document makeEmptyXmlDocument()
public static Element addChildElement(Element element, String childElementName, Document document)
public static Element addChildElementValue(Element element, String childElementName, String childElementValue, Document document)
public static Element addChildElementNSElement(Element element, String childElementName, Document document, String nameSpaceUrl)
public static Element addChildElementNSValue(Element element, String childElementName, String childElementValue, Document document, String nameSpaceUrl)
public static Element addChildElementCDATAValue(Element element, String childElementName, String childElementValue, Document document)
public static List<? extends Element> childElementList(Element element)
public static List<? extends Element> childElementList(Element element, String childElementName)
public static List<? extends Element> childElementList(Element element, Set<String> childElementNames)
public static List<? extends Element> childElementList(Element element, String... childElementNames)
public static List<? extends Element> childElementList(DocumentFragment fragment)
public static List<? extends Node> childNodeList(Node node)
public static Element firstChildElement(Element element, Set<String> childElementNames)
public static Element firstChildElement(Element element, String... childElementNames)
public static Element firstChildElement(Element element)
public static Element firstChildElement(Element element, String childElementName)
public static Element firstChildElement(Element element, String childElementName, String attrName, String attrValue)
public static String childElementValue(Element element, String childElementName)
public static String childElementValue(Element element, String childElementName, String defaultValue)
public static String childElementAttribute(Element element, String childElementName, String attributeName, String defaultValue)
public static String elementValue(Element element)
public static String nodeValue(Node node)
public static String elementAttribute(Element element, String attrName, String defaultValue)
public static boolean checkBoolean(String str)
public static boolean checkBoolean(String str, boolean defaultValue)
public static String nodeNameToJavaName(String nodeName, boolean capitalizeFirst)
public static String getNodeNameIgnorePrefix(Node node)
node
- public static String getTagNameIgnorePrefix(Element element)
element
-