From db0802b6ceaf1fa29ee271bc050386c0f3c1ba93 Mon Sep 17 00:00:00 2001 From: mrglavas Date: Fri, 17 Jun 2005 20:00:57 +0000 Subject: [PATCH] Removing SAX docs. David Megginson removed them [1] from SAX CVS citing that they have fallen out of sync. They were not distributed with SAX 2.0.2. http://cvs.sourceforge.net/viewcvs.py/sax/sax2/docs/?hideattic=0#dirlist git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226241 13f79535-47bb-0310-9956-ffa450edef68 --- java/external/xdocs/sax/changes.html | 297 -------------- java/external/xdocs/sax/features.html | 177 -------- java/external/xdocs/sax/filters.html | 135 ------ java/external/xdocs/sax/namespaces.html | 293 ------------- java/external/xdocs/sax/quick-start.html | 502 ----------------------- java/external/xdocs/sax/sax-style.css | 25 -- java/external/xdocs/sax/sax.html | 39 -- 7 files changed, 1468 deletions(-) delete mode 100644 java/external/xdocs/sax/changes.html delete mode 100644 java/external/xdocs/sax/features.html delete mode 100644 java/external/xdocs/sax/filters.html delete mode 100644 java/external/xdocs/sax/namespaces.html delete mode 100644 java/external/xdocs/sax/quick-start.html delete mode 100644 java/external/xdocs/sax/sax-style.css delete mode 100644 java/external/xdocs/sax/sax.html diff --git a/java/external/xdocs/sax/changes.html b/java/external/xdocs/sax/changes.html deleted file mode 100644 index 9f2a82a..0000000 --- a/java/external/xdocs/sax/changes.html +++ /dev/null @@ -1,297 +0,0 @@ - - - - -SAX2: Changes - - - - -

SAX2: Changes

- -
- -
- - -
-

Changes from SAX 2.0 to SAX 2.0 r2 prerelease

- -

(See the ChangeLog in the distribution for more details.)

- - -
- - -
-

Changes from SAX 2.0prerelease to SAX 2.0

- - - -
- - -
-

Changes from SAX 2.0beta2 to SAX 2.0prerelease

- -

(See the ChangeLog included in the distribution for -more detailed information.)

- - - - -
- - -
-

Changes from SAX 2.0beta to SAX 2.0beta2

- - -
- - -
-

Changes from SAX 1.0 to SAX 2.0beta

- -

The following interfaces and classes have been deprecated, and will -be removed from a future version of SAX; they should be used only for -interaction with SAX1 drivers or applications:

- - - -

The following interfaces and classes have been added to SAX2:

- - - -

SAX2 contains complete Namespace support, which is available by -default from any XMLReader. An XML -reader can also optionally supply raw XML 1.0 names. See SAX2: Namespaces for more details.

- -

An XML reader is fully configurable: it is possible to attempt to -query or change the current value of any feature or property. -Features and properties are identified by fully-qualified URIs, and -parties are free to invent their own names for new extensions. See SAX2: Features and Properties for more -details.

- -

The ContentHandler and Attributes interfaces -are similar to the deprecated DocumentHandler -and AttributeList -interfaces, but they add support for Namespace-related information. -ContentHandler also adds a callback for skipped entities, and -Attributes adds the ability to look up an attribute's index by -name.

- -

The ParserAdapter -class makes a SAX1 Parser behave as a SAX2 XMLReader. The XMLReaderAdapter -class makes a SAX2 XML reader behave as a SAX1 parser. These two -classes should ease the transition from SAX1 to SAX2 by allowing SAX1 -drivers and clients to co-exist with SAX2 drivers and clients in the -same application.

- - -
-

SAX1 Bugs Fixed

- -
-
SAXException
-
Overrode java.lang.Object.toString so that an embedded exception - will give a proper String representation for debugging.
- -
ParserFactory
-
Added missing closing comment so that private constructor is not -commented out.
- -
- -
- -
- -
- -
$Id$
- - - - - diff --git a/java/external/xdocs/sax/features.html b/java/external/xdocs/sax/features.html deleted file mode 100644 index d90294d..0000000 --- a/java/external/xdocs/sax/features.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - -SAX2: Features and Properties - - - - -

SAX2: Features and Properties

- -
- -
- -

SAX2 adds standard methods to query and set features and properties -in an XMLReader. It -is now possible to request an XML reader to validate (or not to -validate) a document, or to internalize (or not to internalize) all -names, using the getFeature, setFeature, -getProperty, and setProperty methods:

- -
-try {
-  if (xmlReader.getFeature("http://xml.org/sax/features/validation")) {
-    System.out.println("Parser is validating.");
-  } else {
-    System.out.println("Parser is not validating.");
-  }
-} catch (SAXException e) {
-  System.out.println("Parser may or may not be validating.");
-}
-
- -

There is no fixed set of features or properties available for SAX2: -implementors are free to define new features and properties as needed. -All feature and property names are fully-qualified URIs (often URLs), -such as "http://www.acme.com/features/foo"; as with Namespace URIs, -people should always define feature and property names based on URIs -that they control.

- -

If an application attempts to query or set a feature that the XML -reader does not recognize, the XML reader throws a SAXNotRecognizedException; if the application attempts to set a -feature state or property value that the XML reader cannot support at -that time, or attempts to modify a feature or property when it is -read-only, the XML reader throws a SAXNotSupportedException.

- -

One important application for properties is getting and setting -extension event handlers, for event types not supported by the four -core SAX2 handlers, EntityResolver, DTDHandler, ContentHandler, and -ErrorHandler. -Outside parties are free to define handlers for any kinds of events, -and to create properties for setting and querying them.

- -

All XML readers are required to recognize the -"http://xml.org/sax/features/namespaces" and the -"http://xml.org/sax/features/namespace-prefixes" features (see below), -and to support a true value for the namespaces property and -a false value for the namespace-prefixes property: these -requirements ensure that all SAX2 XML readers can provide the minimal -required Namespace support for higher-level specs such as RDF, XSL, -XML Schemas, and XLink. XML readers are not required to recognize or -support any other features or any properties, even the core ones -listed below.

- - -
-

Core Features

- -

While anyone is free to define new SAX2 features, there is a core -reference set of features that are application to a wide range of -applications, and that many SAX2 XML readers may choose to support. -Note that features may be read-only or read/write, and that they may -be modifiable only when parsing, or only when not parsing.

- -
- -
http://xml.org/sax/features/namespaces
-
true: Perform Namespace processing.
-
false: Optionally do not perform Namespace processing (implies -namespace-prefixes). See SAX2: -Namespaces for further information.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/features/namespace-prefixes
-
true: Report the original prefixed names and -attributes used for Namespace declarations.
-
false: Do not report attributes used for -Namespace declarations, and optionally do not report original prefixed -names.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/features/string-interning
-
true: All element names, prefixes, attribute -names, Namespace URIs, and local names are internalized using -java.lang.String.intern.
-
false: Names are not necessarily -internalized.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/features/validation
-
true: Report all validation errors (implies -external-general-entities and -external-parameter-entities).
-
false: Do not report validation errors.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/features/external-general-entities
-
true: Include all external general (text) -entities.
-
false: Do not include external general -entities.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/features/external-parameter-entities
-
true: Include all external parameter entities, -including the external DTD subset.
-
false: Do not include any external parameter -entities, even the external DTD subset.
-
access: (parsing) read-only; (not parsing) -read/write
- -
- - -
- - -
-

Core Properties

- -

While anyone is free to define new SAX2 properties, there is a core -reference set of properties that are application to a wide range of -applications, and that many SAX2 XML readers may choose to support. -Note that properties may be read-only or read/write, and that they may -be modifiable only when parsing, or only when not parsing.

- -
- -
http://xml.org/sax/properties/dom-node
-
data type: org.w3c.dom.Node
-
description: When parsing, the current DOM node -being visited if this is a DOM iterator; when not parsing, the root -DOM node for iteration.
-
access: (parsing) read-only; (not parsing) -read/write
- -
http://xml.org/sax/properties/xml-string
-
data type: java.lang.String
-
description: The literal string of characters -that was the source for the current event.
-
access: read-only
- -
- - -
- -
- -
$Id$
- - - diff --git a/java/external/xdocs/sax/filters.html b/java/external/xdocs/sax/filters.html deleted file mode 100644 index 4d6a998..0000000 --- a/java/external/xdocs/sax/filters.html +++ /dev/null @@ -1,135 +0,0 @@ - - - - -SAX2: Filters - - - - -

SAX2: Filters

- -
- -
- -

The SAX interface assumes two basic streams:

- -
    -
  1. a stream of requests flowing from the application to the SAX -driver; and
  2. -
  3. a stream of events (and other information) flowing from the SAX -driver to the application.
  4. -
- -

With SAX1, programmers quickly realized that it was possible to -extend this model to support a processing chain, where requests could -flow through several different components, or filters, before arriving -at the original SAX driver, and events could flow through the same -filters before arriving at the application. Each filter can make -changes to the stream of events as it passes through, but the whole -chain of filters still appears to be a single SAX driver to the -application.

- -

SAX2 formalizes this design technique by adding a new interface, org.xml.sax.XMLFilter, -and a new helper class, org.xml.sax.XMLFilterImpl.

- -

The XMLFilter interface itself is very simple, extending -the basic XMLReader interface with two additional -methods:

- -
-public interface XMLFilter extends XMLReader
-{
-  public abstract void setParent (XMLReader parent);
-  public abstract XMLReader getParent ();
-}
-
- -

In other words, a SAX2 filter is simply an XMLReader that has -another XMLReader as its parent.

- -

In normal use, a filter will implement not only the -XMLFilter interface but also one or all of the various -resolver and handler interfaces (EntityResolver, -DTDHandler, ContentHandler, and -ErrorHandler). To the parent XML reader, the filter is the -client application receiving the events; to the client application, -the filter is the SAX driver producing the events.

- -

The XMLFilterImpl helper class provides a convenient -base for deriving SAX2 filters. This class implements the -XMLFilter, EntityResolver, -DTDHandler, ContentHandler, and -ErrorHandler interfaces. By default, it passes all events -on unmodified, but the derived filter can override specific -methods.

- -

Here's an example of a very simple filter that changes the -Namespace URI http://www.foo.com/ns/ to -http://www.bar.com/ wherever it appears in an element -name (but not an attribute name):

- -
-public class FooFilter extends XMLFilterImpl
-{
-  public FooFilter ()
-  {
-  }
-
-  public FooFilter (XMLReader parent)
-  {
-    super(parent);
-  }
-
-
-  /**
-   * Filter the Namespace URI for start-element events.
-   */
-  public void startElement (String uri, String localName,
-                            String qName, Attributes atts)
-    throws SAXException
-  {
-    if (uri.equals("http://www.foo.com/ns/")) {
-      uri = "http://www.bar.com/ns/";
-    }
-    super.startElement(uri, localName, qName, atts);
-  }
-
-
-  /**
-   * Filter the Namespace URI for end-element events.
-   */
-  public void endElement (String uri, String localName, String qName)
-    throws SAXException
-  {
-    if (uri.equals("http://www.foo.com/ns/")) {
-      uri = "http://www.bar.com/ns/";
-    }
-    super.endElement(uri, localName, qName);
-  }
-
-}
-
- -

Note the use of super.startElement and -super.endElement to send the event on to the client. In a -real filter, it would be good to override the -ContentHandler.startPrefixMapping and -ContentHandler.endPrefixMapping methods as well.

- -

Long filter chains are not always the best approach, but you will -find that it is sometimes easier to build complex XML applications if -you can break them down into a collection of simple SAX filters, each -one reading the events from its parent.

- -
- -
$Id$
- - - diff --git a/java/external/xdocs/sax/namespaces.html b/java/external/xdocs/sax/namespaces.html deleted file mode 100644 index 884dfa5..0000000 --- a/java/external/xdocs/sax/namespaces.html +++ /dev/null @@ -1,293 +0,0 @@ - - - - -SAX2 Namespace Support - - - - -

SAX2 Namespace Support

- -
- -
- -

SAX2 adds XML Namespace support, which is -required for higher-level standards like XSL, XML Schemas, RDF, and XLink. Every implementation of the SAX2 XMLReader interface is -required to support Namespace processing as its default state; some -XML readers may also allow Namespace processing to be disabled or -modified (note to SAX driver writers: there is a helper class, NamespaceSupport, -that can do most of the work of Namespace processing for you).

- -

Namespace processing affects only element and attribute names. -Without Namespace processing, each XML element and attribute has a -single, local name (called the qName), which may contain a -colon; with Namespace processing, each element and attribute has a -two-part name, consisting of an optional URI (equivalent to a Java or -Perl package name) followed by a local name which may not contain a -colon.

- -

SAX is capable of supporting either of these views or both -simultaneously, though XML readers are required to support only the -Namespaces view, and most applications will not need anything -further.

- -
-

1. Namespaces in SAX Events

- -

Namespace support affects the ContentHandler and -Attributes -interfaces.

- - -
-

1.1. Element names

- -

In SAX2, the startElement and endElement callbacks in a content handler look like this:

- -
-public void startElement (String uri, String localName,
-                          String qName, Attributes atts)
-  throws SAXException;
-
-public void endElement (String uri, String localName, String qName)
-  throws SAXException;
-
- -

By default, an XML reader will report a Namespace URI and a local -name for every element, in both the start and end handler. Consider -the following example:

- -
-  <html:hr xmlns:html="http://www.w3.org/1999/xhtml"/>
-
- -

With the default SAX2 Namespace processing, the XML reader would -report a start and end element event with the Namespace URI -"http://www.w3.org/1999/xhtml" and the local name "hr". The XML -reader might also report the original qName "html:hr", but that -parameter might simply be an empty string.

- - -
- - -
-

1.2. Attribute Names

- -

For attributes, you can look up the value of a named attribute -using the getValue method, and you can look up the Namespace URI or local -name of an attribute by its index using the getURI and -getLocalName methods (usually when you're iterating -through the entire attribute list):

- -
-String rdfns = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-String resource = atts.getValue(rdfns, "resource");
-
-for (int i = 0; i < atts.getLength(); i++) {
-  String uri = atts.getURI(i);
-  String localName = atts.getLocalName(i);
-  String value = atts.getValue(i);
-  /* ... */
-}
-
- - -
- - -
-

1.3. Prefix Mappings

- -

In addition to those events, SAX2 reports the scope of Namespace -declarations using the startPrefixMapping and endPrefixMapping methods, so that applications can resolve -prefixes in attribute values or character data if necessary. The -callbacks look like this:

- -
-public void startPrefixMapping (String prefix, String uri)
-  throws SAXException;
-public void endPrefixMapping (String prefix)
-  throws SAXException;
-
- -

For the above example, the XML reader would make the following -callback before the start-element event:

- -
-startPrefixMapping("html", "http://www.w3.org/1999/xhtml")
-
- -

The XML reader would make the following callback after the -end-element event:

- -
-endPrefixMapping("html")
-
- -

The rest of this document applies only to SAX2 applications with -special requirements, such as text editors.

- -
- -
- -
-

2. Configuration

- -
-

2.1. Configuring Namespace Support

- -

The "http://xml.org/features/namespaces" feature controls general -Namespace processing: when this feature is true (the default), -Namespace URIs and local names must be available through the -startElement and endElement callbacks in the ContentHandler -interface, and through the various methods in the Attributes interface, -and start/endPrefixMapping events must be reported.

- -

The "http://xml.org/features/namespace-prefixes" feature controls -the reporting of qNames and Namespace declarations (xmlns* -attributes): when this feature is false (the default), qNames may -optionally be reported, and xmlns* attributes must not be -reported.

- -

The following table summarizes the interaction of these two -features (for general information on using features, see SAX2: Features and Properties):

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namespacesnamespace-prefixesNamespace namesstart/endPrefixMappingqNamesxmlns* attributes
truefalseYESYESunknownNO
truetrueYESYESYESYES
falsefalse(ILLEGAL COMBINATION)
falsetrueunknownunknownYESYES
- -

Note xmlns* attributes will not be -reported unless the namespace-prefixes feature is true (it -is false by default).

- - -
- -
-

2.2. Configuration Example

- -

Consider the following simple sample document:

- -
-<?xml version="1.0"?>
-
-<h:hello xmlns:h="http://www.greeting.com/ns/" id="a1" h:person="David"/>
-
- -

If namespaces is true and namespace-prefixes -is false (the default), then a SAX2 XML reader will report the -following:

- -
    -
  • an element with the Namespace URI "http://www.greeting.com/ns/" and -the local name "hello";
  • -
  • an attribute with no Namespace URI (empty string) and the local -name "id"; and
  • -
  • an attribute with the Namespace URI "http://www.greeting.com/ns/" -and the local name "person".
  • -
- -

If namespaces is true and namespace-prefixes -is true, then a SAX2 XML reader will report the following:

- -
    -
  • an element with the Namespace URI "http://www.greeting.com/ns/", -the local name "hello", and the qName "h:hello";
  • -
  • an attribute with no Namespace URI (empty string), no local name -(empty string), and the qName "xmlns:h";
  • -
  • an attribute with no Namespace URI (empty string), the local -name "id", and the qName "id"; and
  • -
  • an attribute with the Namespace URI "http://www.greeting.com/ns/", -the local name "person", and the qName "h:person".
  • -
- -

If namespaces is false and namespace-prefixes -is true, then a SAX2 XML reader will report the following:

- -
    -
  • an element with the qName "h:hello";
  • -
  • an attribute with the qName "xmlns:h";
  • -
  • an attribute with the qName "id"; and
  • -
  • an attribute with the qName "h:person".
  • -
- - -
- - -
- -
- -
$Id$
- - - diff --git a/java/external/xdocs/sax/quick-start.html b/java/external/xdocs/sax/quick-start.html deleted file mode 100644 index b72ca04..0000000 --- a/java/external/xdocs/sax/quick-start.html +++ /dev/null @@ -1,502 +0,0 @@ - - - - -SAX2: Quick Start - - - - -

SAX2: Quick Start

- -
- -
- -

This document provides a quick-start tutorial for Java programmers -who wish to use SAX2 in their programs.

- - -
-

Requirements

- -

SAX is not an XML parser.

- -

SAX is a common interface implemented for many different XML -parsers (and things that pose as XML parsers), just as the JDBC is a -common interface implemented for many different relational databases -(and things that pose as relational databases). If you want to use -SAX, you'll need all of the following:

- - - - -
- - -
-

Parsing a document

- -

Start by creating a class that extends DefaultHandler:

- -
-import org.xml.sax.helpers.DefaultHandler;
-
-public class MySAXApp extends DefaultHandler
-{
-
-    public MySAXApp ()
-    {
-	super();
-    }
-
-}
-
- -

Now, let's assume that the SAX driver for your XML parser is named -"com.acme.xml.SAXDriver" (this does not really exist: you -must find out the name of the real driver for your parser). -Since this is a Java application, we'll create a static -main method that creates a new instance of this driver -(note the "throws Exception" wimp-out):

- -
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = new com.acme.xml.SAXDriver();
-    }
-
- -

Alternatively, if you don't want to tie your application to a -specific SAX driver, you can use the createXMLReader -method from the XMLReaderFactory class to choose a SAX driver dynamically:

- -
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = XMLReaderFactory.createXMLReader();
-    }
-
- -

In this case, it will be necessary at runtime to set the -org.xml.sax.driver Java system property to the full classname of the -SAX driver, as in

- -
-java -Dorg.xml.sax.driver=com.acme.xml.SAXDriver MySAXApp sample.xml
-
- -

We can use this object to parse XML documents, but first, we have -to register event handlers that the parser can use for reporting -information, using the setContentHandler and setErrorHandler methods from the XMLReader interface. In -a real-world application, the handlers will usually be separate -objects, but for this simple demo, we've bundled the handlers into the -top-level class, so we just have to instantiate the class and register -it with the XML reader:

- -
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = XMLReaderFactory.createXMLReader();
-	MySAXApp handler = new MySAXApp();
-	xr.setContentHandler(handler);
-	xr.setErrorHandler(handler);
-    }
-
- -

This code creates an instance of MySAXApp to receive XML parsing -events, and registers it with the XML reader for regular content -events and error events (there are other kinds, but they're rarely -used). Now, let's assume that all of the command-line args are file -names, and we'll try to parse them one-by-one using the parse method from the XMLReader interface:

- -
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = XMLReaderFactory.createXMLReader();
-	MySAXApp handler = new MySAXApp();
-	xr.setContentHandler(handler);
-	xr.setErrorHandler(handler);
-
-				// Parse each file provided on the
-				// command line.
-	for (int i = 0; i < args.length; i++) {
-	    FileReader r = new FileReader(args[i]);
-	    xr.parse(new InputSource(r));
-	}
-    }
-
- -

Note that each reader must be wrapped in an InputSource object to be parsed. Here's the whole demo class -together (so far):

- -
-import java.io.FileReader;
-
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.XMLReaderFactory;
-import org.xml.sax.helpers.DefaultHandler;
-
-
-public class MySAXApp extends DefaultHandler
-{
-
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = XMLReaderFactory.createXMLReader();
-	MySAXApp handler = new MySAXApp();
-	xr.setContentHandler(handler);
-	xr.setErrorHandler(handler);
-
-				// Parse each file provided on the
-				// command line.
-	for (int i = 0; i < args.length; i++) {
-	    FileReader r = new FileReader(args[i]);
-	    xr.parse(new InputSource(r));
-	}
-    }
-
-
-    public MySAXApp ()
-    {
-	super();
-    }
-}
-
- -

You can compile this code and run it (make sure you specify the SAX -driver class in the org.xml.sax.driver property), but nothing much -will happen unless the document contains malformed XML, because you -have not yet set up your application to handle SAX events.

- - -
- - -
-

Handling events

- -

Things get interesting when you start implementing methods to -respond to XML parsing events (remember that we registered our class -to receive XML parsing events in the previous section). The most -important events are the start and end of the document, the start and -end of elements, and character data.

- -

To find out about the start and end of the document, the client -application implements the startDocument and endDocument methods:

- -
-    public void startDocument ()
-    {
-	System.out.println("Start document");
-    }
-
-    public void endDocument ()
-    {
-	System.out.println("End document");
-    }
-
- -

The start/endDocument event handlers take no arguments. When the -SAX driver finds the beginning of the document, it will invoke the -startDocument method once; when it finds the end, it will -invoke the endDocument method once (if there have been -errors, endDocument may not be invoked).

- -

These examples simply print a message to standard output, but your -application can contain any arbitrary code in these handlers: most -commonly, the code will build some kind of an in-memory tree, produce -output, populate a database, or extract information from the XML -stream.

- -

The SAX driver will signal the start and end of elements in much -the same way, except that it will also pass some parameters to the startElement and endElement methods:

- -
-    public void startElement (String uri, String name,
-			      String qName, Attributes atts)
-    {
-	System.out.println("Start element: {" + uri + "}" + name);
-    }
-
-    public void endElement (String uri, String name, String qName)
-    {
-	System.out.println("End element:   {" + uri + "}" + name);
-    }
-
- -

These methods print a message every time an element starts or ends, -with the Namespace URI in braces before the element's local name. The -qName contains the raw XML 1.0 name, and since not all -SAX drivers will report it, it is best to ignore that parameter for -now.

- -

Finally, SAX2 reports regular character data through the characters method; the following implementation will print all -character data to the screen; it is a little longer because it -pretty-prints the output by escaping special characters:

- -
-    public void characters (char ch[], int start, int length)
-    {
-	System.out.print("Characters:    \"");
-	for (int i = start; i < start + length; i++) {
-	    switch (ch[i]) {
-	    case '\\':
-		System.out.print("\\\\");
-		break;
-	    case '"':
-		System.out.print("\\\"");
-		break;
-	    case '\n':
-		System.out.print("\\n");
-		break;
-	    case '\r':
-		System.out.print("\\r");
-		break;
-	    case '\t':
-		System.out.print("\\t");
-		break;
-	    default:
-		System.out.print(ch[i]);
-		break;
-	    }
-	}
-	System.out.print("\"\n");
-    }
-
- -

Note that a SAX driver is free to chunk the character data any way -it wants, so you cannot count on all of the character data content of -an element arriving in a single characters event.

- - -
- - -
-

Sample SAX2 application

- -

Here is the complete sample application (again, in a serious app -the event handlers would probably be implemented in a separate -class):

- -
-import java.io.FileReader;
-
-import org.xml.sax.XMLReader;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.XMLReaderFactory;
-import org.xml.sax.helpers.DefaultHandler;
-
-
-public class MySAXApp extends DefaultHandler
-{
-
-    public static void main (String args[])
-	throws Exception
-    {
-	XMLReader xr = XMLReaderFactory.createXMLReader();
-	MySAXApp handler = new MySAXApp();
-	xr.setContentHandler(handler);
-	xr.setErrorHandler(handler);
-
-				// Parse each file provided on the
-				// command line.
-	for (int i = 0; i < args.length; i++) {
-	    FileReader r = new FileReader(args[i]);
-	    xr.parse(new InputSource(r));
-	}
-    }
-
-
-    public MySAXApp ()
-    {
-	super();
-    }
-
-
-    ////////////////////////////////////////////////////////////////////
-    // Event handlers.
-    ////////////////////////////////////////////////////////////////////
-
-
-    public void startDocument ()
-    {
-	System.out.println("Start document");
-    }
-
-
-    public void endDocument ()
-    {
-	System.out.println("End document");
-    }
-
-
-    public void startElement (String uri, String name,
-			      String qName, Attributes atts)
-    {
-	System.out.println("Start element: {" + uri + "}" + name);
-    }
-
-
-    public void endElement (String uri, String name, String qName)
-    {
-	System.out.println("End element:   {" + uri + "}" + name);
-    }
-
-
-    public void characters (char ch[], int start, int length)
-    {
-	System.out.print("Characters:    \"");
-	for (int i = start; i < start + length; i++) {
-	    switch (ch[i]) {
-	    case '\\':
-		System.out.print("\\\\");
-		break;
-	    case '"':
-		System.out.print("\\\"");
-		break;
-	    case '\n':
-		System.out.print("\\n");
-		break;
-	    case '\r':
-		System.out.print("\\r");
-		break;
-	    case '\t':
-		System.out.print("\\t");
-		break;
-	    default:
-		System.out.print(ch[i]);
-		break;
-	    }
-	}
-	System.out.print("\"\n");
-    }
-
-}
-
- - -
- - -
-

Sample Output

- -

Consider the following XML document:

- -
-<?xml version="1.0"?>
-
-<poem xmlns="http://www.megginson.com/ns/exp/poetry">
-<title>Roses are Red</title>
-<l>Roses are red,</l>
-<l>Violets are blue;</l>
-<l>Sugar is sweet,</l>
-<l>And I love you.</l>
-</poem>
-
- -

If this document is named roses.xml and there is a -SAX2 driver on your classpath named -com.acme.xml.SAXDriver (this driver does not actually -exist), you can invoke the sample application like this:

- -
-java -Dcom.acme.xml.SAXDriver MySAXApp roses.xml
-
- -

When you run this, you'll get output something like this:

- -
-Start document
-Start element: {http://www.megginson.com/ns/exp/poetry}poem
-Characters:    "\n"
-Start element: {http://www.megginson.com/ns/exp/poetry}title
-Characters:    "Roses are Red"
-End element:   {http://www.megginson.com/ns/exp/poetry}title
-Characters:    "\n"
-Start element: {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "Roses are red,"
-End element:   {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "\n"
-Start element: {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "Violets are blue;"
-End element:   {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "\n"
-Start element: {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "Sugar is sweet,"
-End element:   {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "\n"
-Start element: {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "And I love you."
-End element:   {http://www.megginson.com/ns/exp/poetry}l
-Characters:    "\n"
-End element:   {http://www.megginson.com/ns/exp/poetry}poem
-End document
-
- -

Note that even a short document generates (at least) 25 events: one -for the start and end of each of the six elements used (or, if you -prefer, one for each start tag and one for each end tag), one of each -of the eleven chunks of character data (including whitespace between -elements), one for the start of the document, and one for the end.

- - -
- - -
- -
$Id$
- - - - - diff --git a/java/external/xdocs/sax/sax-style.css b/java/external/xdocs/sax/sax-style.css deleted file mode 100644 index 99ff731..0000000 --- a/java/external/xdocs/sax/sax-style.css +++ /dev/null @@ -1,25 +0,0 @@ -body { - background: white; -} - -h1, h2, h3 { - font-family: arial, sans-serif; - font-weight: bold; -} - -h1 { - font-size: 207%; -} - -h2 { - font-size: 173%; -} - -h3 { - font-size: 144%; -} - -p.copyright { - color: green; - font-style: italic; -} \ No newline at end of file diff --git a/java/external/xdocs/sax/sax.html b/java/external/xdocs/sax/sax.html deleted file mode 100644 index 0549077..0000000 --- a/java/external/xdocs/sax/sax.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - -SAX 2.0/Java - - - - -

SAX 2.0/Java

- -
- -
- -

SAX2 is a new Java-based release of SAX, the Simple API for -XML. A C++ version (at least) is planned as well. SAX2 -introduces configurable features and properties and adds support for -XML Namespaces; it includes adapters so that SAX1 parsers and -applications can interoperate with SAX2.

- - - -
- -
$Id$
- - -