- Interface Parser
- Method Summary
- Method Details
- setLocale
- setEntityResolver
- setDTDHandler
- setDocumentHandler
- setErrorHandler
- parse
- parse
- Java xml parser saxparser
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Constructor Detail
- SAXParser
- Method Detail
- reset
- parse
- parse
- parse
- parse
- parse
- parse
- parse
- parse
- parse
- parse
- getParser
- getXMLReader
- isNamespaceAware
- isValidating
- setProperty
- getProperty
- getSchema
- isXIncludeAware
Interface Parser
This was the main event supplier interface for SAX1; it has been replaced in SAX2 by XMLReader , which includes Namespace support and sophisticated configurability and extensibility.
All SAX1 parsers must implement this basic interface: it allows applications to register handlers for different types of events and to initiate a parse from a URI, or a character stream.
All SAX1 parsers must also implement a zero-argument constructor (though other constructors are also allowed).
SAX1 parsers are reusable but not re-entrant: the application may reuse a parser object (possibly with a different input source) once the first parse has completed successfully, but it may not invoke the parse() methods recursively within a parse.
Method Summary
Method Details
setLocale
Allow an application to request a locale for errors and warnings. SAX parsers are not required to provide localisation for errors and warnings; if they cannot support the requested locale, however, they must throw a SAX exception. Applications may not request a locale change in the middle of a parse.
setEntityResolver
Allow an application to register a custom entity resolver. If the application does not register an entity resolver, the SAX parser will resolve system identifiers and open connections to entities itself (this is the default behaviour implemented in HandlerBase). Applications may register a new or different entity resolver in the middle of a parse, and the SAX parser must begin using the new resolver immediately.
setDTDHandler
Allow an application to register a DTD event handler. If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently ignored (this is the default behaviour implemented by HandlerBase). Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
setDocumentHandler
Allow an application to register a document event handler. If the application does not register a document handler, all document events reported by the SAX parser will be silently ignored (this is the default behaviour implemented by HandlerBase). Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
setErrorHandler
Allow an application to register an error event handler. If the application does not register an error event handler, all error events reported by the SAX parser will be silently ignored, except for fatalError, which will throw a SAXException (this is the default behaviour implemented by HandlerBase). Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
parse
Parse an XML document. The application can use this method to instruct the SAX parser to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI). Applications may not invoke this method while a parse is in progress (they should create a new Parser instead for each additional XML document). Once a parse is complete, an application may reuse the same Parser object, possibly with a different input source.
parse
Parse an XML document from a system identifier (URI). This method is a shortcut for the common case of reading a document from a system identifier. It is the exact equivalent of the following:
parse(new InputSource(systemId));
If the system identifier is a URL, it must be fully resolved by the application before it is passed to the parser.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Java xml parser saxparser
Defines the API that wraps an XMLReader implementation class. In JAXP 1.0, this class wrapped the Parser interface, however this interface was replaced by the XMLReader . For ease of transition, this class continues to support the same name and interface as well as supporting new methods. An instance of this class can be obtained from the SAXParserFactory.newSAXParser() method. Once an instance of this class is obtained, XML can be parsed from a variety of input sources. These input sources are InputStreams, Files, URLs, and SAX InputSources. This static method creates a new factory instance based on a system property setting or uses the platform default if no property has been defined. The system property that controls which Factory implementation to create is named «javax.xml.parsers.SAXParserFactory» . This property names a class that is a concrete subclass of this abstract class. If no property is defined, a platform default will be used. As the content is parsed by the underlying parser, methods of the given HandlerBase or the DefaultHandler are called. Implementors of this class which wrap an underlaying implementation can consider using the ParserAdapter class to initially adapt their SAX1 implementation to work under this revised class.
Constructor Summary
Method Summary
Parse the content described by the giving Uniform Resource Identifier (URI) as XML using the specified DefaultHandler .
Parse the content described by the giving Uniform Resource Identifier (URI) as XML using the specified HandlerBase .
Methods inherited from class java.lang.Object
Constructor Detail
SAXParser
Method Detail
reset
Reset this SAXParser to its original configuration. SAXParser is reset to the same state as when it was created with SAXParserFactory.newSAXParser() . reset() is designed to allow the reuse of existing SAXParser s thus saving resources associated with the creation of new SAXParser s. The reset SAXParser is not guaranteed to have the same Schema Object , e.g. Object.equals(Object obj) . It is guaranteed to have a functionally equal Schema .
parse
public void parse(InputStream is, HandlerBase hb) throws SAXException, IOException
Parse the content of the given InputStream instance as XML using the specified HandlerBase . Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0.
parse
public void parse(InputStream is, HandlerBase hb, String systemId) throws SAXException, IOException
Parse the content of the given InputStream instance as XML using the specified HandlerBase . Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0.
parse
public void parse(InputStream is, DefaultHandler dh) throws SAXException, IOException
parse
public void parse(InputStream is, DefaultHandler dh, String systemId) throws SAXException, IOException
parse
public void parse(String uri, HandlerBase hb) throws SAXException, IOException
Parse the content described by the giving Uniform Resource Identifier (URI) as XML using the specified HandlerBase . Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0
parse
public void parse(String uri, DefaultHandler dh) throws SAXException, IOException
Parse the content described by the giving Uniform Resource Identifier (URI) as XML using the specified DefaultHandler .
parse
public void parse(File f, HandlerBase hb) throws SAXException, IOException
Parse the content of the file specified as XML using the specified HandlerBase . Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0
parse
public void parse(File f, DefaultHandler dh) throws SAXException, IOException
parse
public void parse(InputSource is, HandlerBase hb) throws SAXException, IOException
Parse the content given InputSource as XML using the specified HandlerBase . Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0
parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
getParser
public abstract Parser getParser() throws SAXException
getXMLReader
public abstract XMLReader getXMLReader() throws SAXException
isNamespaceAware
public abstract boolean isNamespaceAware()
isValidating
public abstract boolean isValidating()
setProperty
public abstract void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
- Setting the XMLConstants.ACCESS_EXTERNAL_DTD property restricts the access to external DTDs, external Entity References to the protocols specified by the property. If access is denied during parsing due to the restriction of this property, SAXException will be thrown by the parse methods defined by SAXParser . Setting the XMLConstants.ACCESS_EXTERNAL_SCHEMA property restricts the access to external Schema set by the schemaLocation attribute to the protocols specified by the property. If access is denied during parsing due to the restriction of this property, SAXException will be thrown by the parse methods defined by the SAXParser .
getProperty
public abstract Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException
getSchema
Get a reference to the the Schema being used by the XML processor. If no schema is being used, null is returned.
isXIncludeAware
public boolean isXIncludeAware()