Class XMLUtils

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

public class XMLUtils extends Object
This class holds static methods for use in XML processing.
Author:
John Weatherley
  • Constructor Details

    • XMLUtils

      public XMLUtils()
  • Method Details

    • 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