public final class XMLUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static DocumentBuilder |
createContentParser()
Call
recycleContentParser to reuse the instance. |
static DocumentBuilder |
createDOMParser()
DocumentBuilderFactory.newDocumentBuilder() is called. |
static DocumentBuilder |
createDOMParser(boolean ignoreComments,
boolean ignoringElementContentWhitespace)
Creates the DOM parser.
|
static XMLStreamReader |
createFilteredStreamReader(XMLStreamReader reader,
StreamFilter filter)
Creates the filtered stream reader.
|
static Marshaller |
createMarshaller(Class<?> cls)
Creates the marshaller.
|
static Marshaller |
createMarshaller(String contextPath)
Creates the marshaller.
|
static SAXParser |
createSAXParser()
Call
recycleSAXParser to reuse the instance. |
static Unmarshaller |
createUnmarshaller(Class<?> cls)
Creates the unmarshaller.
|
static Unmarshaller |
createUnmarshaller(String contextPath)
Creates the unmarshaller.
|
static XMLStreamReader |
createXMLStreamReader(InputStream stream)
|
static XMLStreamReader |
createXMLStreamReader(InputStream stream,
String encoding)
|
static XMLStreamReader |
createXMLStreamReader(Reader reader)
|
static XMLStreamWriter |
createXMLStreamWriter(OutputStream stream)
|
static XMLStreamWriter |
createXMLStreamWriter(OutputStream stream,
String encoding)
|
static XMLStreamWriter |
createXMLStreamWriter(Writer writer)
|
static Transformer |
createXMLTransformer()
TransformerFactory.newTransformer() is called. |
static String |
getAttribute(Node node,
String attrName)
Gets the attribute.
|
static List<Element> |
getElementsByTagName(Element node,
String tagName)
Gets the elements by tag name.
|
static Node |
getNextNodeByName(Node node,
String nodeName)
Gets the next node by name.
|
static List<Node> |
getNodesByName(Node node,
String nodeName)
Gets the nodes by name.
|
static String |
getTextContent(Node node)
Gets the text content.
|
static String |
getTextContent(Node node,
boolean ignoreWhiteChar)
Gets the text content.
|
static boolean |
isTextElement(Node node) |
static String |
marshal(Object jaxbEntity)
|
static Map<String,String> |
readAttributes(Node node) |
static void |
recycleContentParser(DocumentBuilder docBuilder)
Recycle content parser.
|
static void |
recycleSAXParser(SAXParser saxParser)
Recycle SAX parser.
|
static <T> T |
unmarshal(Class<? extends T> cls,
String xml)
Unmarshaller#unmarshal(Object, java.io.Writer) is called |
static <T> T |
xmlDecode(String xml)
XMLDecoder.readObject() is called. |
static String |
xmlEncode(Object entity)
XMLEncoder.writeObject(Object) is called. |
public static <T> T unmarshal(Class<? extends T> cls, String xml)
Unmarshaller#unmarshal(Object, java.io.Writer) is calledT - cls - xml - public static Marshaller createMarshaller(String contextPath)
contextPath - public static Marshaller createMarshaller(Class<?> cls)
cls - public static Unmarshaller createUnmarshaller(String contextPath)
contextPath - public static Unmarshaller createUnmarshaller(Class<?> cls)
cls - public static DocumentBuilder createDOMParser()
DocumentBuilderFactory.newDocumentBuilder() is called. client should Cache the result for performance
improvement if this method is called frequently.public static DocumentBuilder createDOMParser(boolean ignoreComments, boolean ignoringElementContentWhitespace)
ignoreComments - ignoringElementContentWhitespace - public static DocumentBuilder createContentParser()
recycleContentParser to reuse the instance.public static void recycleContentParser(DocumentBuilder docBuilder)
docBuilder - public static SAXParser createSAXParser()
recycleSAXParser to reuse the instance.public static void recycleSAXParser(SAXParser saxParser)
saxParser - public static XMLStreamReader createXMLStreamReader(Reader reader)
reader - public static XMLStreamReader createXMLStreamReader(InputStream stream)
stream - public static XMLStreamReader createXMLStreamReader(InputStream stream, String encoding)
stream - encoding - public static XMLStreamReader createFilteredStreamReader(XMLStreamReader reader, StreamFilter filter)
reader - filter - public static XMLStreamWriter createXMLStreamWriter(Writer writer)
writer - public static XMLStreamWriter createXMLStreamWriter(OutputStream stream)
stream - public static XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding)
stream - encoding - public static Transformer createXMLTransformer()
TransformerFactory.newTransformer() is called.public static String xmlEncode(Object entity)
XMLEncoder.writeObject(Object) is called.entity - public static <T> T xmlDecode(String xml)
XMLDecoder.readObject() is called.T - xml - public static List<Element> getElementsByTagName(Element node, String tagName)
node - tagName - public static List<Node> getNodesByName(Node node, String nodeName)
node - nodeName - public static Node getNextNodeByName(Node node, String nodeName)
node - nodeName - public static Map<String,String> readAttributes(Node node)
node - public static String getAttribute(Node node, String attrName)
node - attrName - public static boolean isTextElement(Node node)
node - public static String getTextContent(Node node)
node - Copyright © 2021. All rights reserved.