DLESE Tools
v1.6.0

org.dlese.dpc.xml
Class XMLUtils

java.lang.Object
  extended by org.dlese.dpc.xml.XMLUtils

public class XMLUtils
extends Object

This class holds static methods for use in XML processing.

Author:
John Weatherley

Constructor Summary
XMLUtils()
           
 
Method Summary
static String escapeXml(String xml)
          Escapes the characters in a String using XML entities.
static String removeXMLComments(String input)
          Removes all XML comments from a String.
static StringBuffer stripXmlDeclaration(BufferedReader rdr)
          Strips the XML declaration and DTD declaration from the given XML.
static String xml2json(String xml)
          Convert XML to JSON.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

removeXMLComments

public static String removeXMLComments(String input)
Removes all XML comments from a String.

Parameters:
input - XML String
Returns:
XML with all comments removed

stripXmlDeclaration

public static final StringBuffer stripXmlDeclaration(BufferedReader rdr)
                                              throws IOException
Strips the XML declaration and DTD declaration from the given XML. The resulting content is sutable for insertion inside an existing XML element.

Parameters:
rdr - A BufferedReader containing XML.
Returns:
Content with the XML and DTD declarations stipped out.
Throws:
IOException - If error

xml2json

public static final String xml2json(String xml)
Convert XML to JSON.

Parameters:
xml - An XML String.
Returns:
JSON serialization of the XML or empty string if error.

escapeXml

public static final String escapeXml(String xml)
Escapes the characters in a String using XML entities.

Parameters:
xml - The String to escape, may be null
Returns:
A new escaped String, null if null string input

DLESE Tools
v1.6.0