public class XMLParserextends JaxpParser
Enhanced XML parser for I2P news content with XHTML support.

Extends the base JaxpParser to properly handle mixed text and subnodes in XHTML content while maintaining both output types. Overrides default parsing behavior to ensure correct handling of text nodes and element separation.

Provides custom output methods that recognize special text nodes and uses empty entities for self-closing tags to prevent malformed HTML output.

  • Field Details

    • WHITESPACE

      private static final Pattern WHITESPACE
      Matches spaces, tabs and line breaks
    • _log

      private final Log _log
      Logger for this class.
    • TEXT_NAME

      public static final String TEXT_NAME
      DOM node name the parser uses for character data.
      See Also:
  • Constructor Details

    • XMLParser

      public XMLParser(I2PAppContext ctx)
      Creates a parser that logs under its own class.
      Parameters:
      ctx - the context supplying the log manager for this parser
  • Method Details

    • parse

      public Node parse(Node parentNode, Node domNode, int rank)
      Modified from UPnP JaxpParser.
      Overrides:
      parse in class JaxpParser
      Parameters:
      parentNode - null if at top
      domNode - the DOM node to parse
      rank - parse level, only for debug
      Returns:
      the parsed node, or the parent node, unused except at top level
    • toString

      public static void toString(StringBuilder buf, Node node)
      A replacement for Node.toString(String, boolean), which does not recognize #text.
      Parameters:
      buf - the buffer receiving the XML text of the node and its children
      node - the root of the subtree to render
    • output

      private static void output(StringBuilder buf, Node node, int indentLevel)
      A replacement for Node.output(PrintWriter, int, boolean), which does not recognize #text. Also, we use the empty entity, so <br /> does not turn into <br></br>.
      Parameters:
      buf - the buffer receiving the rendered XML of the node and its children
      node - the root of the subtree to render
      indentLevel - the nesting depth of this node, incremented per child level, currently not rendered