public class XMLScanner extends BasicScanner
getToken() to access the next token, and
getText() to access any associated text.
XMLScanner is designed to buffer between 1-20 tokens on each call to
getToken(), which allows parsers to work with the token
stream during read-cycles from the underlying input stream. Pull-parsers
are therefore faster than the equivalent combination of the push-parser
XMLParser and one of the Builder classes; although the latter offer more
possibilities for customised model-building. XMLScanner implements the
Closeable interface by virtue of inheriting from BasicScanner.
encoding, input, lastChar, symbolStack, textQueue, tokenQueue| Constructor and Description |
|---|
XMLScanner(java.io.File file,
java.lang.String encoding)
Creates a XMLScanner reading from a file, using a specified character
encoding.
|
XMLScanner(java.io.InputStream stream,
java.lang.String encoding)
Creates a XMLScanner reading from a basic InputStream, using a specified
character encoding.
|
XMLScanner(java.io.Reader reader,
java.lang.String encoding)
Creates a XMLScanner reading from a character Reader, using a specified
character encoding.
|
XMLScanner(java.net.URL url,
java.lang.String encoding)
Creates a XMLScanner reading from a URL, using a specified character
encoding.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getContext()
Returns the XML context in which a syntax error is detected.
|
protected void |
scanAnyContent()
Scans the input stream for arbitrary XML content, populating the token
stream.
|
private void |
scanAttribute()
Scans an attribute-value pair.
|
private void |
scanCloseElement()
Scans an XML element closing tag.
|
private void |
scanComment()
Scans an XML comment.
|
private void |
scanDeclaration()
Scans the opening XML declaration.
|
private void |
scanDoctype()
Scans a Doctype declaration.
|
private void |
scanEscapedData()
Scans escaped character data inside a CDATA section.
|
private void |
scanInstruction()
Scans an XML processing instruction.
|
private void |
scanOpenElement()
Scans an XML element opening tag.
|
private void |
scanTextContent()
Scans non-markup content as PCDATA text.
|
close, endOfStream, getEncoding, getLineNumber, getText, getToken, scanEntityReference, scanExactly, scanKeyword, scanNameToken, scanQuotedValue, skipSpaceencodingError, semanticError, syntaxErrorpublic XMLScanner(java.io.File file,
java.lang.String encoding)
throws java.io.FileNotFoundException,
java.io.UnsupportedEncodingException
file - the input file.encoding - the name of the character encoding.java.io.FileNotFoundException - if the file cannot be found or opened.java.io.UnsupportedEncodingException - if the character encoding is not
supported.public XMLScanner(java.net.URL url,
java.lang.String encoding)
throws java.io.IOException,
java.io.UnsupportedEncodingException
openStream() method.url - the absolute URL giving the location of the XML data.encoding - the name of the character encoding.java.io.IOException - if the attempt to connect to the URL and open an
input stream to read from it fails.java.io.UnsupportedEncodingException - if the character encoding is not
supported.public XMLScanner(java.io.InputStream stream,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
stream - the basic InputStream.encoding - the name of the character encoding.java.io.UnsupportedEncodingException - if the character encoding is not
supported.public XMLScanner(java.io.Reader reader,
java.lang.String encoding)
reader - the character Reader.encoding - the name of the character encoding.public java.lang.String getContext()
getContext in class BasicScannerprotected void scanAnyContent()
throws java.io.UnsupportedEncodingException,
java.io.IOException,
SyntaxError
scanAnyContent in class BasicScannerjava.io.UnsupportedEncodingException - if a decoding fault occurs.java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanDeclaration()
throws java.io.UnsupportedEncodingException,
java.io.IOException,
SyntaxError
java.io.EOFException - if the input stream contains no data.java.io.IOException - if an input stream error occurs.java.io.UnsupportedEncodingException - if a decoding fault occurs.SyntaxError - if there is whitespace before the XML declaration,
or if the XML contains syntax errors.private void scanInstruction()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanDoctype()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.java.io.EOFException - if premature end of input is detected.SyntaxError - if an XML syntax error is detected.private void scanComment()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.java.io.EOFException - if premature end of input is detected.SyntaxError - if an XML syntax error is detected.private void scanOpenElement()
throws java.io.IOException
java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanCloseElement()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanAttribute()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanTextContent()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.SyntaxError - if an XML syntax error is detected.private void scanEscapedData()
throws java.io.IOException,
SyntaxError
java.io.IOException - if an input stream error is detected.java.io.EOFException - if premature end of input is detected.SyntaxError - if an XML syntax error is detected.