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 ofRSyntaxTextArea
.For a more complete XML parsing/validation solution, see the RSTALanguageSupport project's
XmlLanguageSupport
class.- Version:
- 1.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
XmlParser.Handler
Callback notified when errors are found in the XML document.
-
Field Summary
Fields Modifier and Type Field Description private org.xml.sax.EntityResolver
entityResolver
private DefaultParseResult
result
private javax.xml.parsers.SAXParserFactory
spf
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isValidating()
Returns whether this parser does DTD validation.ParseResult
parse(RSyntaxDocument doc, java.lang.String style)
Parses input from the specified document.void
setValidating(boolean validating)
Sets whether this parser will use DTD validation if required.-
Methods inherited from class org.fife.ui.rsyntaxtextarea.parser.AbstractParser
getHyperlinkListener, getImageBase, isEnabled, setEnabled, setHyperlinkListener
-
-
-
-
Field Detail
-
spf
private javax.xml.parsers.SAXParserFactory spf
-
result
private DefaultParseResult result
-
entityResolver
private org.xml.sax.EntityResolver entityResolver
-
-
Constructor Detail
-
XmlParser
public XmlParser()
-
XmlParser
public XmlParser(org.xml.sax.EntityResolver resolver)
Constructor allowing DTD validation of documents.- Parameters:
resolver
- An entity resolver to use if validation is enabled.- See Also:
setValidating(boolean)
-
-
Method Detail
-
isValidating
public boolean isValidating()
Returns whether this parser does DTD validation.- Returns:
- Whether this parser does DTD validation.
- See Also:
setValidating(boolean)
-
parse
public ParseResult parse(RSyntaxDocument doc, java.lang.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 asSyntaxConstants.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 istrue
, documents must specify a DOCTYPE, and you should have used the constructor specifying an entity resolver.- See Also:
isValidating()
-
-