[jdom-interest] Using JDOM....to get Parser / SAX / Namespace neutrality / indepe ndance?

adam flinton aflinton at armature.com
Thu Oct 19 06:39:11 PDT 2000


Dear All,

I am helping to build a free app which transfers between XML & DBMS'es (both
2 Db & 2 XML) called XML-DBMS http://www.rpbourret.com/xmldbms/index.htm


We are currently working on Version 2 which amongst other things should use
schema's instead of DTD'es, a GUI & properties files for choosing the JDBC
connection & the XML parser (@ the mo' the latter 2 have to be edited in the
source code & then recompiled).

I have been reading how JDOM is meant to be faster than std DOM & even
(gasp) easier to use... The easy to use part would be usefull however
obviously the speed (esp when dealing with DB'es holding potentially a lot
of data / producing large documents) is crucial.

Firstly anyone with an interest in both XML<>DB interaction & JDOM then if
you've got the time.....<G>.

However one of the things which we need to do (& which I am going to try &
do) is the abstraction of the XML parser. I have looked @ JAXP but it does
not seem to support DOM2 plus I have the feeling that it won't keep up with
the speed with which XML is moving. 

How does JDOM achieve Parser Independance? 

@ the mo' the create document code needs to have one class for each parser
e.g. for Xerces:

<CODE>
import org.w3c.dom.Document;

public class DF_Xerces implements DocumentFactory
{

   public DF_Xerces()
   {
   }   


   public Document createDocument() throws DocumentFactoryException
   {
	  try
	  {
		 return new org.apache.xerces.dom.DocumentImpl();
	  }
	  catch (Exception e)
	  {
		 throw new DocumentFactoryException(e.getMessage());
	  }
   }   
}

</CODE>

vs Say for the IBM XML4J you have:

<CODE>
import org.w3c.dom.Document;

public class DF_IBM implements DocumentFactory
{

   public DF_IBM()
   {
   }   


   public Document createDocument() throws DocumentFactoryException
   {
	  try
	  {
		 return new com.ibm.xml.parser.TXDocument();
	  }
	  catch (Exception e)
	  {
		 throw new DocumentFactoryException(e.getMessage());
	  }
   }

</CODE>

So how would you deal with a similar thing in JDOM?

Equally there are similar probs with namespace e.g. DOM2:

<CODE>
package de.tudarmstadt.ito.domutils;

import org.w3c.dom.Node;

public class NQ_DOM2 extends NameQualifierImpl
{
   public String getLocalName(Node node)
   {
	  String localName = null;

	  int nodeType = node.getNodeType();


	  if ((nodeType == Node.ELEMENT_NODE) || (nodeType == 
Node.ATTRIBUTE_NODE))
	  {
		 localName = node.getLocalName();
	  }
	  if (localName == null) localName = node.getNodeName();
	  return localName;
   }   


   public String getNamespaceURI(Node node)
   {
	  return node.getNamespaceURI();
   }

</CODE>

vs say IBM

<CODE>

package de.tudarmstadt.ito.domutils;

import org.w3c.dom.Node;
import com.ibm.xml.parser.Namespace;

public class NQ_IBM extends NameQualifierImpl
{
   public String getLocalName(Node node)
   {
	  int nodeType = node.getNodeType();

	  if ((nodeType == Node.ELEMENT_NODE) || (nodeType ==
Node.ATTRIBUTE_NODE))
	  {
		 return ((Namespace)node).getNSLocalName();
	  }
	  return node.getNodeName();
   }   

   public String getNamespaceURI(Node node)
   {
	  int nodeType = node.getNodeType();

	  if ((nodeType == Node.ELEMENT_NODE) || (nodeType ==
Node.ATTRIBUTE_NODE))
	  {
		 return ((Namespace)node).getNSName();
	  }
	  return null;
   }   
}

</CODE>

     

So 
(a) Can JDOM Help vs say DOM & Sax to get away from differences in
implementations of Sax, DOM & Namespaces?
(b) Will JDOM speed stuff up compared to DOM
(c) Anyone knowledgeable in JDOM who wants to help?

Adam



More information about the jdom-interest mailing list