[
Lists Home |
Date Index |
Thread Index
]
- From: Mike Dierken <mike@DataChannel.com>
- To: Kay Michael <Michael.Kay@icl.com>, 'XML-DEV' <xml-dev@ic.ac.uk>
- Date: Thu, 22 Apr 1999 09:49:26 -0700
When the DataChannel XML Document class loads & parses XML text, it uses one
'input scanner' but allows any 'parser' class to be used.
The IXMLInputScanner interface is used to read characters from the source
data (input stream, text string, etc.).
The IXMLDOMParser interface (based on IXMLTokenizer and IXMLParser) is used
to build the DOM representation.
The Document class has methods for specifiying which IXMLDOMParser to use.
Here is the list:
"com.datachannel.xml.tokenizer.parser.BasicParser" (default)
"com.datachannel.xml.tokenizer.parser.DTDValidatingParser" (based on
BasicParser)
"com.datachannel.xml.tokenizer.parser.XMLDOMParser" (based on
DTDValidatingParser)
Here are the methods in Document for specifying different parsers:
public void setParserClassName(String parserClassName)
public IXMLDOMParser createParser()
You can use call the 'setParserClassName()' on the Document class, or extend
the class & override the 'createParser()' class (to initialize the parser
with more information, for example).
The internal 'load()' method will create the parser, tell it what the
document instance is, tell it what the input scanner is and then start the
parser on its way. The parser then inserts things it finds into the
specified document instance.
There is some documentation on the xdev.datachannel.com site:
http://xdev.datachannel.com/downloads/xjparser/documentation/#properties
Mike D
DataChannel
-----Original Message-----
From: Kay Michael [mailto:Michael.Kay@icl.com]
Sent: Thursday, April 22, 1999 8:44 AM
To: 'XML-DEV'
Subject: RE: DOM - Creating Documents
Ronald Bourret asked how do you create a Document using various products.
For the record, here are the relevant drivers from SAXON:
Datachannel:
public Document build (InputSource source)
throws java.io.IOException, org.xml.sax.SAXException
{
com.datachannel.xml.om.Document doc = new
com.datachannel.xml.om.Document();
try {
if (null != source.getByteStream()) {
// byte stream supplied
doc.loadFromInputStream(source.getByteStream());
} else if (null != source.getCharacterStream()) {
// character stream supplied [horrible code and not tested!]
Reader r = source.getCharacterStream();
StringBuffer sb = new StringBuffer(10000);
char[] cbuf = new char[10000];
int bytes = 0;
while (true) {
bytes = r.read(cbuf);
if (bytes<0) break; // end of file
sb.append(cbuf, 0, bytes);
}
doc.loadXML(sb.toString());
} else {
// URL supplied
doc.load(source.getSystemId());
}
}
catch (Exception e) {
throw new SAXException(e);
}
return doc;
}
Docuverse:
public Document build(InputSource source)
{
DOM dom = new DOM();
dom.setReader(new SAXONFreedomDriver());
return dom.openDocument(source);
}
// inner class
/**
*
* SAXONFreedomDriver<BR>
* Subclasses DOM-SDK's SAXReader class to use a supplied parser<BR>
* This class is used to interface SAXON with Docuverse
* and is of no direct concern to applications.
*
*/
private class SAXONFreedomDriver extends
com.docuverse.dom.util.SAXReader
{
protected Parser createParser (com.docuverse.dom.DOM dom)
{
return givenparser;
}
}
IBM:
public Document build (InputSource source)
throws java.io.IOException, org.xml.sax.SAXException
{
Document doc = null;
com.ibm.xml.parser.Parser p;
try {
p = new com.ibm.xml.parser.Parser(source.getSystemId());
if (null != source.getByteStream()) {
doc = p.readStream(source.getByteStream());
} else if (null != source.getCharacterStream()) {
doc = p.readStream(source.getCharacterStream());
} else {
doc = p.readStream(
p.getInputStream(
source.getSystemId(),
null,
source.getSystemId()));
}
} catch (Exception e) {
p = null;
throw new SAXException(e);
}
return doc;
}
ORACLE:
public Document build(InputSource source)
throws java.io.IOException, org.xml.sax.SAXException
{
oracle.xml.parser.XMLParser p = new oracle.xml.parser.XMLParser();
p.parse(source);
return p.getDocument();
}
SUN:
public Document build(InputSource source)
throws java.io.IOException, org.xml.sax.SAXException
{
XmlDocumentBuilder b = new XmlDocumentBuilder();
b.setDisableNamespaces(true);
givenparser.setDocumentHandler(b);
givenparser.parse(source);
return b.getDocument();
}
Interesting if nothing else for the sheer variety of different ways of
achieving the same thing! Note some of these allow you to select your parser
first, others don't.
Mike Kay
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN
981-02-3594-1
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following
message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)
|