public final class XMLUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Document |
createDOMDocument()
Construct a new (empty) DOM Document and return it.
|
static String |
escape(Object content)
Escapes all the XML special characters in a
String using numerical XML entities. |
static String |
escapeAttributeValue(Object content)
Escapes all the XML special characters and left curly bracket in a
String using numerical XML
entities, so that the resulting string can safely be used as an XML attribute value. |
static String |
escapeElementContent(Object content)
Escapes the XML special characters in a
String using numerical XML entities, so that the resulting
string can safely be used as an XML text node. |
static String |
escapeXMLComment(String content)
XML comment does not support some characters inside its content but there is no official escaping/unescaping for
it so we made our own.
|
static String |
extractXML(Node node,
int start,
int length)
Extracts a well-formed XML fragment from the given DOM tree.
|
static String |
formatXMLContent(String content)
Parse and pretty pint a XML content.
|
static Document |
parse(LSInput source)
Parse a DOM Document from a source.
|
static String |
serialize(Node node)
Serialize a DOM Node into a string, including the XML declaration at the start.
|
static String |
serialize(Node node,
boolean withXmlDeclaration)
Serialize a DOM Node into a string, with an optional XML declaration at the start.
|
static String |
transform(Source xml,
Source xslt)
Apply an XSLT transformation to a Document.
|
static String |
unescape(Object content)
Unescape encoded special XML characters.
|
static String |
unescapeXMLComment(String content)
XML comment does not support some characters inside its content but there is no official escaping/unescaping for
it so we made our own.
|
public static String extractXML(Node node, int start, int length)
node - the root of the DOM tree where the extraction takes placestart - the index of the first characterlength - the maximum number of characters in text nodes to include in the returned fragmentpublic static String escapeXMLComment(String content)
content - the XML comment content to escapepublic static String unescapeXMLComment(String content)
content - the XML comment content to unescapeescapeXMLComment(String)public static String escape(Object content)
String using numerical XML entities. Specifically,
escapes <, >, ", ', & and {. Left curly bracket is included here to protect against {{/html}} in
xwiki 2.x syntax.content - the text to escape, may be nullString, null if null inputpublic static String escapeAttributeValue(Object content)
String using numerical XML
entities, so that the resulting string can safely be used as an XML attribute value. Specifically, escapes <,
>, ", ', & and {. Left curly bracket is included here to protect against {{/html}} in xwiki 2.x syntax.content - the text to escape, may be nullString, null if null inputpublic static String escapeElementContent(Object content)
String using numerical XML entities, so that the resulting
string can safely be used as an XML text node. Specifically, escapes <, >, and &.content - the text to escape, may be nullString, null if null inputpublic static String unescape(Object content)
content - the text to decode, may be nullnull if null inputpublic static Document createDOMDocument()
public static Document parse(LSInput source)
source - the source input to parsenull if the parsing failed.public static String serialize(Node node)
node - the node to exportpublic static String serialize(Node node, boolean withXmlDeclaration)
node - the node to exportwithXmlDeclaration - whether to output the XML declaration or notnullpublic static String transform(Source xml, Source xslt)
xml - the document to transformxslt - the stylesheet to applynull if an error occurs or null xml or xslt inputpublic static String formatXMLContent(String content) throws TransformerFactoryConfigurationError, TransformerException
content - the XML content to formatTransformerFactoryConfigurationError - when failing to create a
TransformerFactoryConfigurationErrorTransformerException - when failing to transform the contentCopyright © 2004–2015 XWiki. All rights reserved.