Class XmlParser

java.lang.Object
org.fife.ui.rsyntaxtextarea.parser.AbstractParser
org.fife.ui.rsyntaxtextarea.parser.XmlParser
All Implemented Interfaces:
Parser

public class XmlParser extends AbstractParser
A parser for XML documents. Adds squiggle underlines for any XML errors found (though most XML parsers don't really have error recovery and so only can find one error at a time).

This class isn't actually used by RSyntaxTextArea anywhere, but you can install and use it yourself. Doing so is as simple as:

 XmlParser xmlParser = new XmlParser();
 textArea.addParser(xmlParser);
 
To support DTD validation, specify an entity resolver when creating the parser, and enable validation like so:
 XmlParser xmlParser = new XmlParser(new MyEntityResolver());
 xmlParser.setValidating(true);
 textArea.addParser(xmlParser);
 
Also note that a single instance of this class can be installed on multiple instances of RSyntaxTextArea.

For a more complete XML parsing/validation solution, see the RSTALanguageSupport project's XmlLanguageSupport class.

Version:
1.1
  • Field Details

  • Constructor Details

    • XmlParser

      public XmlParser()
    • XmlParser

      public XmlParser(EntityResolver resolver)
      Constructor allowing DTD validation of documents.
      Parameters:
      resolver - An entity resolver to use if validation is enabled.
      See Also:
  • Method Details

    • isValidating

      public boolean isValidating()
      Returns whether this parser does DTD validation.
      Returns:
      Whether this parser does DTD validation.
      See Also:
    • parse

      public ParseResult parse(RSyntaxDocument doc, String style)
      Description copied from interface: Parser
      Parses input from the specified document.
      Parameters:
      doc - The document to parse. This document is in a read lock, so it cannot be modified while parsing is occurring.
      style - The language being rendered, such as SyntaxConstants.SYNTAX_STYLE_JAVA.
      Returns:
      An object describing the section of the document parsed and the results. This is guaranteed to be non-null.
    • setValidating

      public void setValidating(boolean validating)
      Sets whether this parser will use DTD validation if required.
      Parameters:
      validating - Whether DTD validation should be enabled. If this is true, documents must specify a DOCTYPE, and you should have used the constructor specifying an entity resolver.
      See Also: