org.xwiki.xml
Class XMLUtils

java.lang.Object
  extended by org.xwiki.xml.XMLUtils

public final class XMLUtils
extends java.lang.Object

XML Utility methods.

Since:
1.6M1
Version:
$Id$

Method Summary
static java.lang.String escape(java.lang.Object content)
          Escapes all the XML special characters in a String using numerical XML entities.
static java.lang.String escapeAttributeValue(java.lang.Object content)
          Escapes all the XML special characters in a String using numerical XML entities, so that the resulting string can safely be used as an XML attribute value.
static java.lang.String escapeElementContent(java.lang.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 java.lang.String escapeXMLComment(java.lang.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 java.lang.String extractXML(org.w3c.dom.Node node, int start, int length)
          Extracts a well-formed XML fragment from the given DOM tree.
static java.lang.String unescape(java.lang.Object content)
          Unescape encoded special XML characters.
static java.lang.String unescapeXMLComment(java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractXML

public static java.lang.String extractXML(org.w3c.dom.Node node,
                                          int start,
                                          int length)
Extracts a well-formed XML fragment from the given DOM tree.

Parameters:
node - the root of the DOM tree where the extraction takes place
start - the index of the first character
length - the maximum number of characters in text nodes to include in the returned fragment
Returns:
a well-formed XML fragment starting at the given character index and having up to the specified length, summing only the characters in text nodes
Since:
1.6M2

escapeXMLComment

public static java.lang.String escapeXMLComment(java.lang.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.

Parameters:
content - the XML comment content to escape
Returns:
the escaped content.
Since:
1.9M2

unescapeXMLComment

public static java.lang.String unescapeXMLComment(java.lang.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.

Parameters:
content - the XML comment content to unescape
Returns:
the unescaped content.
Since:
1.9M2
See Also:
escapeXMLComment(String)

escape

public static java.lang.String escape(java.lang.Object content)
Escapes all the XML special characters in a String using numerical XML entities. Specifically, escapes <, >, ", ' and &.

Parameters:
content - the text to escape, may be null
Returns:
a new escaped String, null if null input

escapeAttributeValue

public static java.lang.String escapeAttributeValue(java.lang.Object content)
Escapes all the XML special characters in a String using numerical XML entities, so that the resulting string can safely be used as an XML attribute value. Specifically, escapes <, >, ", ' and &.

Parameters:
content - the text to escape, may be null
Returns:
a new escaped String, null if null input

escapeElementContent

public static java.lang.String escapeElementContent(java.lang.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. Specifically, escapes <, >, and &.

Parameters:
content - the text to escape, may be null
Returns:
a new escaped String, null if null input

unescape

public static java.lang.String unescape(java.lang.Object content)
Unescape encoded special XML characters. Only >, < &, " and ' are unescaped, since they are the only ones that affect the resulting markup.

Parameters:
content - the text to decode, may be null
Returns:
unescaped content, null if null input


Copyright © 2004-2011 XWiki. All Rights Reserved.