Title: RE: Are these two equivalent?

There does exist a non implementation specific way for creating a document -- JAXP 1.1. With JAXP 1.1, you can achieve your goal by doing following:

...
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; 
...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element ele = doc.createElement("test");
doc.appendChild(ele);

Then at deployment time, you can specify which parser to use by setting system properties like this (assume you are using Xerces):

java -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl YourClass

By default, the factories are org.apache.crimson.jaxp.SAXParserFactoryImpl and org.apache.crimson.jaxp.DocumentBuilderFactoryImpl.

For more details go to http://java.sun.com/xml/

-Lei




-----Original Message-----
From: Jason Rizer [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 05, 2001 4:42 PM
To: [EMAIL PROTECTED]
Subject: Are these two equivalent?


Hello.  I know this is a pretty rudimentary question,
but is there any difference between the following two
sets of code?:

// Sample 1
DocumentImpl doc = new DocumentImpl( );
ElementImpl ele = new ElementImpl(doc, "test");

// Sample 2
Document doc = new DocumentImpl( );
Element ele = doc.createElement("test");

Am I correct to assume that craeteElement( ) returns a
ElementImpl?  The second way is obviously better
because it removes the specific depencey in the code
on org.apache.xerces.dom.  Is there, however, a non
implementation specific way to factory the document?
I'd like to be able to swap out the xerces parser for
another without changing my code.  Is this possible?
Thanks in advance!

-Jason

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to