public class DomParser
extends java.lang.Object
Document
object to or from XML.
https://www.journaldev.com/1237/java-convert-string-to-xml-document-and-xml-document-to-stringModifier and Type | Field and Description |
---|---|
static java.lang.String |
W3CDOM
Codes a string as a w3c dom document
|
Constructor and Description |
---|
DomParser() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addW3cSpec(java.lang.String xmlStr)
Add the special characters indicating a string of
org.wc3.dom XML format that should
not be converted into anything else. |
static boolean |
isW3cDom(java.lang.Object xmlElem)
Return true if the object is a w3c
Document type. |
static boolean |
isW3cDom(java.lang.String xmlElem)
Return true if the object is a w3c
Document type. |
static org.w3c.dom.Document |
parse(java.lang.String toParse)
Parse a String description of a
Document object back into a Java object. |
static java.lang.String |
prettyFormatXml(org.w3c.dom.Document doc,
boolean keepDeclaration)
Pretty format the w3c document and return the string representation.
|
static java.lang.String |
removeW3cSpec(java.lang.String xmlStr)
Remove the special characters indicating a string of
org.wc3.dom XML format
that should not be converted into anything else. |
static java.lang.String |
serialize(org.w3c.dom.Document toSerialize)
Serialize a
Document object to XML. |
public static final java.lang.String W3CDOM
public static boolean isW3cDom(java.lang.String xmlElem)
Document
type.xmlElem
- the string parameter.public static boolean isW3cDom(java.lang.Object xmlElem)
Document
type.xmlElem
- the element parameter.public static java.lang.String serialize(org.w3c.dom.Document toSerialize) throws java.lang.Exception
Document
object to XML.toSerialize
- the ByteArray object to serialize.java.lang.Exception
- any error.public static org.w3c.dom.Document parse(java.lang.String toParse) throws java.lang.Exception
Document
object back into a Java object.toParse
- the XML description to parse.java.lang.Exception
- any error.public static java.lang.String addW3cSpec(java.lang.String xmlStr)
org.wc3.dom XML
format that should
not be converted into anything else. The Parsers however will automatically
try to remove this coding as part of a final parsing event.xmlStr
- the original String.public static java.lang.String removeW3cSpec(java.lang.String xmlStr)
org.wc3.dom XML
format
that should not be converted into anything else.xmlStr
- the original String with the special characters included.public static java.lang.String prettyFormatXml(org.w3c.dom.Document doc, boolean keepDeclaration) throws java.lang.Exception
doc
- the w3c document.keepDeclaration
- true if keep the header declaration.java.lang.Exception
- any error.