Class XMLUtils

java.lang.Object
com.nomagic.magicreport.helper.XMLUtils

@OpenApiAll public final class XMLUtils extends Object
Provides utilities for XML.
Since:
Jan 10, 2006 5:27:40 PM
  • Method Details

    • filter

      public static String filter(CharSequence value)
      Filter the specified string for characters that are sensitive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.
      Parameters:
      value - The string to be filtered and returned
      Returns:
      string after filtered
    • filterExcludeLineBreak

      public static String filterExcludeLineBreak(String value)
      Same as filter(CharSequence) but exclude line break. e.g. \r and \n
      Parameters:
      value - The string to be filtered and returned
      Returns:
      string after filtered
    • filterIncludeCustomLineBreak

      public static String filterIncludeCustomLineBreak(String value, String lineBreakReplacement)
      Same as filter(CharSequence) but replace linebreak with lineBreakReplacement
      Parameters:
      value - The string to be filtered and returned
      lineBreakReplacement - string to replace the linebreak
      Returns:
      string after filtered
    • htmlPlainText

      public static String htmlPlainText(String xmlContent)
      Strip all tag element and convert all special characters to plain text.
      Parameters:
      xmlContent - the xml content
      Returns:
      plain text.
    • xmlPlainText

      public static String xmlPlainText(String xmlContent)
      Strip all tag element and convert all special characters to plain text.
      Parameters:
      xmlContent - the xml content
      Returns:
      plain text.
    • getElementsByTagName

      public static NodeList getElementsByTagName(Element element, String tagName)
      Returns a List over the direct children of the given element with the given tag name. Element.getElementsByTagName(String) gives the corresponding elements in the whole descendance. This method return only direct descendance of element.
      Parameters:
      element - The parent element
      tagName - The name of the desired child
      Returns:
      A List of children or zero length of List if children element is not found.
    • skipBOM

      public static void skipBOM(Reader reader) throws IOException
      Skip the BOM character. Some XML may contains a byte-order mark (BOM). The XML parser will get the error if XML contains BOM character. This method also remove or mark skip byte when reader contain BOM.

      The BOM is the Unicode character at code point U+FEFF ("zero-width no-break space") when that character is used to denote the endianness of a string of UCS/Unicode characters encoded in UTF-16 or UTF-32.

      Parameters:
      reader - Reader
      Throws:
      IOException - If the stream does not support mark(), or reset()
    • skipBOM

      public static void skipBOM(InputStream inputStream) throws IOException
      Skip the BOM character. Some XML may contains a byte-order mark (BOM). The XML parser will get the error if XML contains BOM character. This method also remove or mark skip byte when reader contain BOM.

      The BOM is the Unicode character at code point U+FEFF ("zero-width no-break space") when that character is used to denote the endianness of a string of UCS/Unicode characters encoded in UTF-16 or UTF-32.

      Parameters:
      inputStream - InputStream
      Throws:
      IOException - If the stream does not support mark(), or reset()