[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: DOM - Creating Documents

  • From: Kay Michael <Michael.Kay@i...>
  • To: "'XML-DEV'" <xml-dev@i...>
  • Date: Thu, 22 Apr 1999 16:43:47 +0100

getcharacterstream
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@i...
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@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.