Class XmlUtil

java.lang.Object
com.pnfsoftware.jeb.util.encoding.xml.XmlUtil

public class XmlUtil extends Object
XML utility methods.
  • Method Details

    • createSecureDocumentBuilderFactory

      public static DocumentBuilderFactory createSecureDocumentBuilderFactory(boolean disallowDoctypeDecl) throws ParserConfigurationException
      Create a safe DocumentBuilderFactory object.
      Parameters:
      disallowDoctypeDecl -
      Returns:
      the factory object
      Throws:
      ParserConfigurationException
    • isSpace

      public static boolean isSpace(int codePoint)
      Determine whether the provided code point is a white space character.
      Parameters:
      codePoint - Unicode code point
      Returns:
      true if the code point is XML whitespace or a Java space character
    • skipSomeSpaces

      public static int skipSomeSpaces(String str, int idx)
      Skip 1+ WSP characters.
      Parameters:
      str - input string
      idx - start index
      Returns:
      new index after skipped whitespace
    • skipSpaces

      public static int skipSpaces(String str, int idx)
      Skip 0+ WSP characters.
      Parameters:
      str - input string
      idx - start index
      Returns:
      new index after skipped whitespace
    • skipWSP

      public static int skipWSP(String str, int idx, int minSpaceCount)
      Skip WSP characters.
      Parameters:
      str - string
      idx - start index
      minSpaceCount - the method will raise if fewer WSP chars were skipped
      Returns:
      new index, after skipping WSP chars
    • readToken

      public static int readToken(String str, int idx, Collection<Integer> stoppers, String[] atoken)
      Read a token.
      Parameters:
      str - input string
      idx - token start (cannot be a wsp); may be a single-quote or double-quote
      stoppers - optional code points that terminate an unquoted token
      atoken - output token
      Returns:
      index immediately after the token
    • readToken

      public static int readToken(String str, int idx, Collection<Integer> stoppers, String[] atoken, boolean mustBeQuoted, boolean handleBackslashAxmlStyle)
      Read a token.
      Parameters:
      str - input string
      idx - token start (cannot be a wsp); may be a single-quote or double-quote
      stoppers - optional code points that terminate an unquoted token
      atoken - output token
      mustBeQuoted - true if the token must start with a quote
      handleBackslashAxmlStyle - true to decode Android resource backslash escapes
      Returns:
      index immediately after the token
    • compare

      public static boolean compare(String str, int idx, String expected)
      Compare a substring with an expected literal.
      Parameters:
      str - input string
      idx - substring start index
      expected - expected literal
      Returns:
      true if expected starts at idx
    • compareCI

      public static boolean compareCI(String str, int idx, String expected)
      Compare a substring with an expected literal, ignoring case.
      Parameters:
      str - input string
      idx - substring start index
      expected - expected literal
      Returns:
      true if expected starts at idx, ignoring case
    • getFirstChildElement

      public static Element getFirstChildElement(Element e, String childName)
      Find the first direct child element with the requested name.
      Parameters:
      e - parent element
      childName - child tag name
      Returns:
      first matching child element, or null
    • getChildrenElements

      public static List<Element> getChildrenElements(Element e, String childName)
      Find all direct child elements with the requested name.
      Parameters:
      e - parent element
      childName - child tag name
      Returns:
      list of matching child elements
    • format

      public static String format(Document doc)
      Format a document as text.
      Parameters:
      doc - input document
      Returns:
      textual representation of the document