tango.text.xml.SaxParser

License:

BSD style: see license.txt

Version:

Initial release: February 2008

Authors:

stonecobra, Kris

Acknowledgements:

Many thanks to the entire group that came up with SAX as an API, and then had the foresight to place it into the public domain so that it can become a de-facto standard. It may not be the best XML API, but it sure is handy. For more information, see http://www.saxproject.org.
struct Attribute(Ch = char)
Single attributes are represented by this struct.
class SaxHandler(Ch = char) [public]
Receive notification of the logical content of a document.

This is the main interface that most SAX applications

implement:

if the application needs to be informed of basic parsing events, it implements this interface and registers an instance with the SAX parser using the {@link org.xml.sax.XMLReader#setContentHandler setContentHandler} method. The parser uses the instance to report basic document-related events like the start and end of elements and character data.

The order of events in this interface is very important, and mirrors the order of information in the document itself. For example, all of an element's content (character data, processing instructions, and/or subelements) will appear, in order, between the startElement event and the corresponding endElement event.

This interface is similar to the now-deprecated SAX 1.0 DocumentHandler interface, but it adds support for Namespaces and for reporting skipped entities (in non-validating XML processors).

Implementors should note that there is also a ContentHandler class in the java.net package; that means that it's probably a bad idea to do

import java.net.*;
 import org.xml.sax.*;
 

In fact, "import ...*" is usually a sign of sloppy programming anyway, so the user should consider this a feature rather than a bug.

@since SAX 2.0 @author David Megginson @version 2.0.1+ (sax2r3pre1) @see org.xml.sax.XMLReader @see org.xml.sax.ErrorHandler
void setDocumentLocator(Locator!(Ch) locator) [public]
Receive an object for locating the origin of SAX document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation SAX event callbacks after {@link #startDocument startDocument} returns and before {@link #endDocument endDocument} is called. The application should not attempt to use it at any other time.

@param locator an object that can return the location of any SAX document event @see org.xml.sax.Locator
void startDocument() [public]
Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other event callbacks (except for {@link #setDocumentLocator setDocumentLocator}).

@throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception @see #endDocument
void endDocument() [public]
Receive notification of the end of a document.

There is an apparent contradiction between the documentation for this method and the documentation for {@link org.xml.sax.ErrorHandler#fatalError}. Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

@throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception @see #startDocument
void startPrefixMapping(const(Ch)[] prefix, const(Ch)[] uri) [public]
Begin the scope of a prefix-URI Namespace mapping.

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding {@link #startElement startElement} event, and all {@link #endPrefixMapping endPrefixMapping} events will occur immediately after the corresponding {@link #endElement endElement} event, but their order is not otherwise guaranteed.

There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.

@param prefix the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix. @param uri the Namespace URI the prefix is mapped to @throws org.xml.sax.SAXException the client may throw an exception during processing @see #endPrefixMapping @see #startElement
void endPrefixMapping(const(Ch)[] prefix) [public]
End the scope of a prefix-URI mapping.

See {@link #startPrefixMapping startPrefixMapping} for details. These events will always occur immediately after the corresponding {@link #endElement endElement} event, but the order of {@link #endPrefixMapping endPrefixMapping} events is not otherwise guaranteed.

@param prefix the prefix that was being mapped. This is the empty string when a default mapping scope ends. @throws org.xml.sax.SAXException the client may throw an exception during processing @see #startPrefixMapping @see #endElement
void startElement(const(Ch)[] uri, const(Ch)[] localName, const(Ch)[] qName, Attribute!(Ch)[] atts) [public]
Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding {@link #endElement endElement} event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each

element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes

properties:

  • the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
  • the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Like {@link #characters characters()}, attribute values may have characters that need more than one char value.

@param uri the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed @param localName the local name (without prefix), or the empty string if Namespace processing is not being performed @param qName the qualified name (with prefix), or the empty string if qualified names are not available @param atts the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception @see #endElement @see org.xml.sax.Attributes @see org.xml.sax.helpers.AttributesImpl
void endElement(const(Ch)[] uri, const(Ch)[] localName, const(Ch)[] qName) [public]
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding {@link #startElement startElement} event for every endElement event (even when the element is empty).

For information on the names, see startElement.

@param uri the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed @param localName the local name (without prefix), or the empty string if Namespace processing is not being performed @param qName the qualified XML name (with prefix), or the empty string if qualified names are not available @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception
void characters(const(Ch)[] ch) [public]
Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the {@link #ignorableWhitespace ignorableWhitespace} method rather than this one (validating parsers must do so).

@param ch the characters from the XML document @param start the start position in the array @param length the number of characters to read from the array @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception @see #ignorableWhitespace @see org.xml.sax.Locator
void ignorableWhitespace(Ch[] ch) [public]
Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

@param ch the characters from the XML document @param start the start position in the array @param length the number of characters to read from the array @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception @see #characters
void processingInstruction(const(Ch)[] target, const(Ch)[] data) [public]
Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser must never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

Like {@link #characters characters()}, processing instruction data may have characters that need more than one char value.

@param target the processing instruction target @param data the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception
void skippedEntity(const(Ch)[] name) [public]
Receive notification of a skipped entity. This is not called for entity references within markup constructs such as element start tags or markup declarations. (The XML recommendation requires reporting skipped external entities. SAX also reports internal entity expansion/non-expansion, except within markup constructs.)

The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

@param name the name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]" @throws org.xml.sax.SAXException any SAX exception, possibly wrapping another exception
interface EntityResolver(Ch = char) [public]
Basic interface for resolving entities.

If a SAX application needs to implement customized handling for external entities, it must implement this interface and register an instance with the SAX driver using the {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver} method.

The XML reader will then allow the application to intercept any external entities (including the external DTD subset and external parameter entities, if any) before including them.

Many SAX applications will not need to implement this interface, but it will be especially useful for applications that build XML documents from databases or other specialised input sources, or for applications that use URI types other than URLs.

The following resolver would provide the application with a special character stream for the entity with the system identifier "http://www.myhost.com/today":

 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;

public class MyResolver implements EntityResolver { public InputSource resolveEntity (String publicId, String systemId) { if (systemId.equals("http://www.myhost.com/today")) { // return a special input source MyReader reader = new MyReader(); return new InputSource(reader); } else { // use the default behaviour return null; } } }

The application can also use this interface to redirect system identifiers to local URIs or to look up replacements in a catalog (possibly by using the public identifier).

@since SAX 1.0 @author David Megginson @version 2.0.1 (sax2r2) @see org.xml.sax.XMLReader#setEntityResolver @see org.xml.sax.InputSource
InputStream resolveEntity(const(Ch)[] publicId, const(Ch)[] systemId) [public]
Allow the application to resolve external entities.

The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

@param publicId The public identifier of the external entity being referenced, or null if none was supplied. @param systemId The system identifier of the external entity being referenced. @return An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @exception java.io.IOException A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource. @see org.xml.sax.InputSource
interface ErrorHandler(Ch = char) [public]
Basic interface for SAX error handlers.

If a SAX application needs to implement customized error handling, it must implement this interface and then register an instance with the XML reader using the {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler} method. The parser will then report all errors and warnings through this interface.

WARNING: If an application does not register an ErrorHandler, XML parsing errors will go unreported, except that SAXParseExceptions will be thrown for fatal errors. In order to detect validity errors, an ErrorHandler that does something with {@link #error error()} calls must be registered.

For XML processing errors, a SAX driver must use this interface in preference to throwing an exception: it is up to the application to decide whether to throw an exception for different types of errors and warnings. Note, however, that there is no requirement that the parser continue to report additional errors after a call to {@link #fatalError fatalError}. In other words, a SAX driver class may throw an exception after reporting any fatalError. Also parsers may throw appropriate exceptions for non-XML errors. For example, {@link XMLReader#parse XMLReader.parse()} would throw an IOException for errors accessing entities or the document.

@since SAX 1.0 @author David Megginson @version 2.0.1+ (sax2r3pre1) @see org.xml.sax.XMLReader#setErrorHandler @see org.xml.sax.SAXParseException
void warning(SAXException exception) [public]
Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

@param exception The warning information encapsulated in a SAX parse exception. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.SAXParseException
void error(SAXException exception) [public]
Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

@param exception The error information encapsulated in a SAX parse exception. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.SAXParseException
void fatalError(SAXException exception) [public]
Receive notification of a non-recoverable error.

There is an apparent contradiction between the documentation for this method and the documentation for {@link org.xml.sax.ContentHandler#endDocument}. Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.

This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.

The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error

messages:

in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.

@param exception The error information encapsulated in a SAX parse exception. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.SAXParseException
interface Locator(Ch = char) [public]
Interface for associating a SAX event with a document location.

If a SAX parser provides location information to the SAX application, it does so by implementing this interface and then passing an instance to the application using the content handler's {@link org.xml.sax.ContentHandler#setDocumentLocator setDocumentLocator} method. The application can use the object to obtain the location of any other SAX event in the XML source document.

Note that the results returned by the object will be valid only during the scope of each callback method: the application will receive unpredictable results if it attempts to use the locator at any other time, or after parsing completes.

SAX parsers are not required to supply a locator, but they are very strongly encouraged to do so. If the parser supplies a locator, it must do so before reporting any other document events. If no locator has been set by the time the application receives the {@link org.xml.sax.ContentHandler#startDocument startDocument} event, the application should assume that a locator is not available.

@since SAX 1.0 @author David Megginson @version 2.0.1 (sax2r2) @see org.xml.sax.ContentHandler#setDocumentLocator
const(Ch)[] getPublicId() [public]
Return the public identifier for the current document event.

The return value is the public identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

@return A string containing the public identifier, or null if none is available. @see #getSystemId
const(Ch)[] getSystemId() [public]
Return the system identifier for the current document event.

The return value is the system identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application. For example, a file name must always be provided as a file:... URL, and other kinds of relative URI are also resolved against their bases.

@return A string containing the system identifier, or null if none is available. @see #getPublicId
int getLineNumber() [public]
Return the line number where the current document event ends. Lines are delimited by line ends, which are defined in the XML specification.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. In some cases, these "line" numbers match what would be displayed as columns, and in others they may not match the source text due to internal entity expansion.

The return value is an approximation of the line number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first line is line 1.

@return The line number, or -1 if none is available. @see #getColumnNumber
int getColumnNumber() [public]
Return the column number where the current document event ends. This is one-based number of Java char values since the last line end.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. For example, when lines contain combining character sequences, wide characters, surrogate pairs, or bi-directional text, the value may not correspond to the column in a text editor's display.

The return value is an approximation of the column number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first column in each line is column 1.

@return The column number, or -1 if none is available. @see #getLineNumber
class SAXException : Exception [public]
Encapsulate a general SAX error or warning.

This class can contain basic error or warning information from either the XML parser or the application: a parser writer or application writer can subclass it to provide additional functionality. SAX handlers may throw this exception or any exception subclassed from it.

If the application needs to pass through other types of exceptions, it must wrap those exceptions in a SAXException or an exception derived from a SAXException.

If the parser or application needs to include information about a specific location in an XML document, it should use the {@link org.xml.sax.SAXParseException SAXParseException} subclass.

@since SAX 1.0 @author David Megginson @version 2.0.1 (sax2r2) @see org.xml.sax.SAXParseException
this() [public]
Create a new SAXException.
this(immutable(char)[] message) [public]
Create a new SAXException.
@param message The error or warning message.
this(Exception e) [public]
Create a new SAXException wrapping an existing exception.

The existing exception will be embedded in the new one, and its message will become the default message for the SAXException.

@param e The exception to be wrapped in a SAXException.
this(immutable(char)[] message, Exception e) [public]
Create a new SAXException from an existing exception.

The existing exception will be embedded in the new one, but the new exception will have its own message.

@param message The detail message. @param e The exception to be wrapped in a SAXException.
immutable(char)[] message() [public]
Return a detail message for this exception.

If there is an embedded exception, and if the SAXException has no detail message of its own, this method will return the detail message from the embedded exception.

@return The error or warning message.
class SaxParser(Ch = char) : XMLReader!(Ch), Locator!(Ch)
this() [public]
bool getFeature(const(Ch)[] name) [public]
Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in specific contexts, such as before, during, or after a parse. Also, some feature values may not be programmatically accessible. (In the case of an adapter for SAX1 {@link Parser}, there is no implementation-independent way to expose whether the underlying parser is performing validation, expanding external entities, and so forth.)

All XMLReaders are required to recognize the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Typical usage is something like this:

 XMLReader r = new MySAXDriver();

// try to activate validation try { r.setFeature("http://xml.org/sax/features/validation", true); } catch (SAXException e) { System.err.println("Cannot activate validation."); }

// register event handlers r.setContentHandler(new MyContentHandler()); r.setErrorHandler(new MyErrorHandler());

// parse the first document try { r.parse("http://www.foo.com/mydoc.xml"); } catch (IOException e) { System.err.println("I/O exception reading XML document"); } catch (SAXException e) { System.err.println("XML exception reading document."); }

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.

@param name The feature name, which is a fully-qualified URI. @return The current value of the feature (true or false). @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the feature name but cannot determine its value at this time. @see #setFeature
void setFeature(const(Ch)[] name, bool value) [public]
Set the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to true and http://xml.org/sax/features/namespace-prefixes to false.

@param name The feature name, which is a fully-qualified URI. @param value The requested value of the feature (true or false). @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the feature name but cannot set the requested value. @see #getFeature
Object getProperty(const(Ch)[] name) [public]
Look up the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize any specific property names, though an initial core set is documented for SAX2.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.

@param name The property name, which is a fully-qualified URI. @return The current value of the property. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the property name but cannot determine its value at this time. @see #setProperty
void setProperty(const(Ch)[] name, Object value) [public]
Set the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize setting any specific property names, though a core set is defined by SAX2.

This method is also the standard mechanism for setting extended handlers.

@param name The property name, which is a fully-qualified URI. @param value The requested value for the property. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the property name but cannot set the requested value.
void setEntityResolver(EntityResolver!(Ch) resolver) [public]
Allow an application to register an entity resolver.

If the application does not register an entity resolver, the XMLReader will perform its own default resolution.

Applications may register a new or different resolver in the middle of a parse, and the SAX parser must begin using the new resolver immediately.

@param resolver The entity resolver. @see #getEntityResolver
EntityResolver!(Ch) getEntityResolver() [public]
Return the current entity resolver.
@return The current entity resolver, or null if none has been registered. @see #setEntityResolver
void setSaxHandler(SaxHandler!(Ch) handler) [public]
Allow an application to register a content event handler.

If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.

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.

@param handler The content handler. @see #getContentHandler
SaxHandler!(Ch) getSaxHandler() [public]
Return the current content handler.
@return The current content handler, or null if none has been registered. @see #setContentHandler
void setErrorHandler(ErrorHandler!(Ch) handler) [public]
Allow an application to register an error event handler.

If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.

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.

@param handler The error handler. @see #getErrorHandler
ErrorHandler!(Ch) getErrorHandler() [public]
Return the current error handler.
@return The current error handler, or null if none has been registered. @see #setErrorHandler
void parse(const(Ch)[] content) [public]
Parse an XML document from a character array.
@param content The actual document content. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @exception java.io.IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application. @see #parse(org.xml.sax.InputSource)
void parse() [public]
void setContent(const(Ch)[] content) [public]
void reset() [public]
const(Ch)[] getPublicId() [public]
Return the public identifier for the current document event.

The return value is the public identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

@return A string containing the public identifier, or null if none is available. @see #getSystemId
const(Ch)[] getSystemId() [public]
Return the system identifier for the current document event.

The return value is the system identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application. For example, a file name must always be provided as a file:... URL, and other kinds of relative URI are also resolved against their bases.

@return A string containing the system identifier, or null if none is available. @see #getPublicId
int getLineNumber() [public]
Return the line number where the current document event ends. Lines are delimited by line ends, which are defined in the XML specification.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. In some cases, these "line" numbers match what would be displayed as columns, and in others they may not match the source text due to internal entity expansion.

The return value is an approximation of the line number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first line is line 1.

@return The line number, or -1 if none is available. @see #getColumnNumber
int getColumnNumber() [public]
Return the column number where the current document event ends. This is one-based number of Java char values since the last line end.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. For example, when lines contain combining character sequences, wide characters, surrogate pairs, or bi-directional text, the value may not correspond to the column in a text editor's display.

The return value is an approximation of the column number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first column in each line is column 1.

@return The column number, or -1 if none is available. @see #getLineNumber
class XMLFilter(Ch = char) : XMLReader [public, abstract]
Interface for an XML filter.

An XML filter is like an XML reader, except that it obtains its events from another XML reader rather than a primary source like an XML document or database. Filters can modify a stream of events as they pass on to the final application.

The XMLFilterImpl helper class provides a convenient base for creating SAX2 filters, by passing on all {@link org.xml.sax.EntityResolver EntityResolver}, {@link org.xml.sax.DTDHandler DTDHandler}, {@link org.xml.sax.ContentHandler ContentHandler} and {@link org.xml.sax.ErrorHandler ErrorHandler} events automatically.

@since SAX 2.0 @author David Megginson @version 2.0.1 (sax2r2) @see org.xml.sax.helpers.XMLFilterImpl
void setParent(XMLReader parent) [public]
Set the parent reader.

This method allows the application to link the filter to a parent reader (which may be another filter). The argument may not be null.

@param parent The parent reader.
XMLReader getParent() [public]
Get the parent reader.

This method allows the application to query the parent reader (which may be another filter). It is generally a bad idea to perform any operations on the parent reader

directly:

they should all pass through this filter.

@return The parent filter, or null if none has been set.
class XMLFilterImpl(Ch = char) : SaxHandler, XMLFilter, EntityResolver, ErrorHandler [public]
Base class for deriving an XML filter.

This class is designed to sit between an {@link org.xml.sax.XMLReader XMLReader} and the client application's event handlers. By default, it does nothing but pass requests up to the reader and events on to the handlers unmodified, but subclasses can override specific methods to modify the event stream or the configuration requests as they pass through.

@since SAX 2.0 @author David Megginson @version 2.0.1 (sax2r2) @see org.xml.sax.XMLFilter @see org.xml.sax.XMLReader @see org.xml.sax.EntityResolver @see org.xml.sax.ContentHandler @see org.xml.sax.ErrorHandler
this() [public]
Construct an empty XML filter, with no parent.

This filter will have no parent: you must assign a parent before you start a parse or do any configuration with setFeature or setProperty, unless you use this as a pure event consumer rather than as an {@link XMLReader}.

@see org.xml.sax.XMLReader#setFeature @see org.xml.sax.XMLReader#setProperty @see #setParent
this(XMLReader parent) [public]
Construct an XML filter with the specified parent.
@see #setParent @see #getParent
void setParent(XMLReader parent) [public]
Set the parent reader.

This is the {@link org.xml.sax.XMLReader XMLReader} from which this filter will obtain its events and to which it will pass its configuration requests. The parent may itself be another filter.

If there is no parent reader set, any attempt to parse or to set or get a feature or property will fail.

@param parent The parent XML reader. @see #getParent
XMLReader getParent() [public]
Get the parent reader.
@return The parent XML reader, or null if none is set. @see #setParent
void setFeature(const(Ch)[] name, bool value) [public]
Set the value of a feature.

This will always fail if the parent is null.

@param name The feature name. @param value The requested feature value. @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved from the parent. @exception org.xml.sax.SAXNotSupportedException When the parent recognizes the feature name but cannot set the requested value.
bool getFeature(const(Ch)[] name) [public]
Look up the value of a feature.

This will always fail if the parent is null.

@param name The feature name. @return The current value of the feature. @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved from the parent. @exception org.xml.sax.SAXNotSupportedException When the parent recognizes the feature name but cannot determine its value at this time.
void setProperty(const(Ch)[] name, Object value) [public]
Set the value of a property.

This will always fail if the parent is null.

@param name The property name. @param value The requested property value. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved from the parent. @exception org.xml.sax.SAXNotSupportedException When the parent recognizes the property name but cannot set the requested value.
Object getProperty(const(Ch)[] name) [public]
Look up the value of a property.
@param name The property name. @return The current value of the property. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved from the parent. @exception org.xml.sax.SAXNotSupportedException When the parent recognizes the property name but cannot determine its value at this time.
void setEntityResolver(EntityResolver resolver) [public]
Set the entity resolver.
@param resolver The new entity resolver.
EntityResolver getEntityResolver() [public]
Get the current entity resolver.
@return The current entity resolver, or null if none was set.
void setSaxHandler(SaxHandler handler) [public]
Set the content event handler.
@param handler the new content handler
SaxHandler getSaxHandler() [public]
Get the content event handler.
@return The current content handler, or null if none was set.
void setErrorHandler(ErrorHandler handler) [public]
Set the error event handler.
@param handler the new error handler
ErrorHandler getErrorHandler() [public]
Get the current error event handler.
@return The current error handler, or null if none was set.
void parse(const(Ch)[] content) [public]
Parse the given content.
@param input The input source for the document entity. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @exception java.io.IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
InputStream resolveEntity(const(Ch)[] publicId, const(Ch)[] systemId) [public]
Filter an external entity resolution.
@param publicId The entity's public identifier, or null. @param systemId The entity's system identifier. @return A new InputSource or null for the default. @exception org.xml.sax.SAXException The client may throw an exception during processing. @exception java.io.IOException The client may throw an I/O-related exception while obtaining the new InputSource.
void setDocumentLocator(Locator locator) [public]
Filter a new document locator event.
@param locator The document locator.
void startDocument() [public]
Filter a start document event.
@exception org.xml.sax.SAXException The client may throw an exception during processing.
void endDocument() [public]
Filter an end document event.
@exception org.xml.sax.SAXException The client may throw an exception during processing.
void startPrefixMapping(const(Ch)[] prefix, const(Ch)[] uri) [public]
Filter a start Namespace prefix mapping event.
@param prefix The Namespace prefix. @param uri The Namespace URI. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void endPrefixMapping(const(Ch)[] prefix) [public]
Filter an end Namespace prefix mapping event.
@param prefix The Namespace prefix. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void startElement(const(Ch)[] uri, const(Ch)[] localName, const(Ch)[] qName, Attribute[] atts) [public]
Filter a start element event.
@param uri The element's Namespace URI, or the empty string. @param localName The element's local name, or the empty string. @param qName The element's qualified (prefixed) name, or the empty string. @param atts The element's attributes. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void endElement(const(Ch)[] uri, const(Ch)[] localName, const(Ch)[] qName) [public]
Filter an end element event.
@param uri The element's Namespace URI, or the empty string. @param localName The element's local name, or the empty string. @param qName The element's qualified (prefixed) name, or the empty string. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void characters(Ch[] ch) [public]
Filter a character data event.
@param ch An array of characters. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void ignorableWhitespace(Ch[] ch) [public]
Filter an ignorable whitespace event.
@param ch An array of characters. @param start The starting position in the array. @param length The number of characters to use from the array. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void processingInstruction(const(Ch)[] target, const(Ch)[] data) [public]
Filter a processing instruction event.
@param target The processing instruction target. @param data The text following the target. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void skippedEntity(const(Ch)[] name) [public]
Filter a skipped entity event.
@param name The name of the skipped entity. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void warning(SAXException e) [public]
Filter a warning event.
@param e The warning as an exception. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void error(SAXException e) [public]
Filter an error event.
@param e The error as an exception. @exception org.xml.sax.SAXException The client may throw an exception during processing.
void fatalError(SAXException e) [public]
Filter a fatal error event.
@param e The error as an exception. @exception org.xml.sax.SAXException The client may throw an exception during processing.
interface XMLReader(Ch = char) [public]
Interface for reading an XML document using callbacks.

XMLReader is the interface that an XML parser's SAX2 driver must implement. This interface allows an application to set and query features and properties in the parser, to register event handlers for document processing, and to initiate a document parse.

All SAX interfaces are assumed to be synchronous: the {@link #parse parse} methods must not return until parsing is complete, and readers must wait for an event-handler callback to return before reporting the next event.

This interface replaces the (now deprecated) SAX 1.0 {@link org.xml.sax.Parser Parser} interface. The XMLReader interface contains two important enhancements over the old Parser interface (as well as some minor ones):

  1. it adds a standard way to query and set features and properties; and
  2. it adds Namespace support, which is required for many higher-level XML standards.

There are adapters available to convert a SAX1 Parser to a SAX2 XMLReader and vice-versa.

@since SAX 2.0 @author David Megginson @version 2.0.1+ (sax2r3pre1) @see org.xml.sax.XMLFilter @see org.xml.sax.helpers.ParserAdapter @see org.xml.sax.helpers.XMLReaderAdapter
bool getFeature(const(Ch)[] name) [public]
Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in specific contexts, such as before, during, or after a parse. Also, some feature values may not be programmatically accessible. (In the case of an adapter for SAX1 {@link Parser}, there is no implementation-independent way to expose whether the underlying parser is performing validation, expanding external entities, and so forth.)

All XMLReaders are required to recognize the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Typical usage is something like this:

 XMLReader r = new MySAXDriver();

// try to activate validation try { r.setFeature("http://xml.org/sax/features/validation", true); } catch (SAXException e) { System.err.println("Cannot activate validation."); }

// register event handlers r.setContentHandler(new MyContentHandler()); r.setErrorHandler(new MyErrorHandler());

// parse the first document try { r.parse("http://www.foo.com/mydoc.xml"); } catch (IOException e) { System.err.println("I/O exception reading XML document"); } catch (SAXException e) { System.err.println("XML exception reading document."); }

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.

@param name The feature name, which is a fully-qualified URI. @return The current value of the feature (true or false). @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the feature name but cannot determine its value at this time. @see #setFeature
void setFeature(const(Ch)[] name, bool value) [public]
Set the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to true and http://xml.org/sax/features/namespace-prefixes to false.

@param name The feature name, which is a fully-qualified URI. @param value The requested value of the feature (true or false). @exception org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the feature name but cannot set the requested value. @see #getFeature
Object getProperty(const(Ch)[] name) [public]
Look up the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize any specific property names, though an initial core set is documented for SAX2.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.

@param name The property name, which is a fully-qualified URI. @return The current value of the property. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the property name but cannot determine its value at this time. @see #setProperty
void setProperty(const(Ch)[] name, Object value) [public]
Set the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize setting any specific property names, though a core set is defined by SAX2.

This method is also the standard mechanism for setting extended handlers.

@param name The property name, which is a fully-qualified URI. @param value The requested value for the property. @exception org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved. @exception org.xml.sax.SAXNotSupportedException When the XMLReader recognizes the property name but cannot set the requested value.
void setEntityResolver(EntityResolver!(Ch) resolver) [public]
Allow an application to register an entity resolver.

If the application does not register an entity resolver, the XMLReader will perform its own default resolution.

Applications may register a new or different resolver in the middle of a parse, and the SAX parser must begin using the new resolver immediately.

@param resolver The entity resolver. @see #getEntityResolver
EntityResolver!(Ch) getEntityResolver() [public]
Return the current entity resolver.
@return The current entity resolver, or null if none has been registered. @see #setEntityResolver
void setSaxHandler(SaxHandler!(Ch) handler) [public]
Allow an application to register a content event handler.

If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.

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.

@param handler The content handler. @see #getContentHandler
SaxHandler!(Ch) getSaxHandler() [public]
Return the current content handler.
@return The current content handler, or null if none has been registered. @see #setContentHandler
void setErrorHandler(ErrorHandler!(Ch) handler) [public]
Allow an application to register an error event handler.

If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.

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.

@param handler The error handler. @see #getErrorHandler
ErrorHandler!(Ch) getErrorHandler() [public]
Return the current error handler.
@return The current error handler, or null if none has been registered. @see #setErrorHandler
void parse(const(Ch)[] content) [public]
Parse an XML document from a character array.
@param content The actual document content. @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @exception java.io.IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application. @see #parse(org.xml.sax.InputSource)
void parse() [public]
void setContent(const(Ch)[] content) [public]