@author Alejandro Abdelnur
@author Alejandro Abdelnur
Typically, when you parse an XML document, you do not want the parse to barf on badly-formed XML with an exception. XmlReader therefore prints error and warning messages to an output stream, which is by default System.out, but can be set to another stream to allow an application to capture this output (to display it in a GUI, for example). A "verbose" flag can be used to make the XML reader print out lots and lots of other information as well. Once the parse is complete, the caller should use the getErrorCount() method to see if there were any errors.
This parser is capable of resolving external entities using either public IDs or system IDs. System IDs are usually given as a complete URL to the given file. Public IDs are given as partial pathnames to which the parser prepends a locally known location for libraries of XML files. In Diva, the partial pathname (eg "graph.dtd") is looked up in the default resource bundle in the diva.resource package. DTDs that can be recognized as "public" must therefore be entered into diva/resource/Defaults.properties file. If both IDs are given, this parser tries to use the public ID first. @author Steve Neuendorffer, John Reekie @version $Id: XmlReader.java,v 1.24 2005/12/30 17:56:26 cxh Exp $
Read data from an XML file into a graph of objects. One or more objects get created as a result of parsing an XML file.
Created: Feb 22, 2003
Copyright: Copyright (c) 2003
Assumptions: none
Requires: ReaderContentHandler, XmlException
Required by: nothing
Revision History:
2003-04-21 Changed to use JAXP instead of Xerces.
2004-04-14 Support for a configuration object
Example:
XmlReader reader = new XmlReader("filename.xml", "base.pkg.of.classes"); SalesLot rootObject = (SalesLot)reader.getRootObject(); Could read a structure like this (where SalesLot is the root Java object and the root XML element): <SalesLot> <Car> <make>Saab</make> <model>93</model> <year>2001</year> </Car> <Car> <make>Saab</make> <model>95</model> <year>2002</year> </Car> </SalesLot> The SalesLot object would implement a method called addCar(Car newCar) which would add each of the Car elements to a Collection. Car would implement setMake(String theMake), setModel(String theModel) and setYear(String theYear).@author Donald Kittle
Purpose:Provide a wrapper for an org.xml.sax.XMLReader instance and define some extra event methods that can be used by TopLink during the unmarshal process. These events are no ops in this class, but may be overridden in subclasses.
Responsibilities
Note: despite its name, this interface does not extend the standard Java {@link java.io.Reader Reader} interface, because reading XML is a fundamentally different activity than reading character data.
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 parsingis 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 interfacecontains two important enhancements over the old Parser interface (as well as some minor ones):
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|