[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnu.xml.dom.DomText implements Text and NodeList.

From: Pedro Izecksohn
Subject: Re: gnu.xml.dom.DomText implements Text and NodeList.
Date: Tue, 10 Jan 2006 04:31:55 -0400
User-agent: KMail/1.7.2

>We ask that people agree to the GNU Classpath Hackers requirements
>before granting CVS commit permissions. You can find them at:

I'm submiting source code to this list to be included in the GNU classpath 
project, assuring that I wrote this code and it is legally mine, accepting 
that it will be distributed under the GNU General Public License with the 
linking exception, and I'm donating this code to the Free Software 

If I need to sign on paper, tell me from where may I download the model.

>It really should be a static inner class (since no state of the outer
>class is used).

inner: Inside which one? DocumentType, ProcessingInstruction, Comment, Text,
CDATASection and Notation have no children.


  DomCDATASection extends DomText,
  DomText extends DomCharacterData,
  DomComment extends DomCharacterData, 

it would be better to modify DomCharacterData.

DomDoctype, DomNotation and DomProcessingInstruction seem (to the test case 
below) to be OK.

May be a public class as below.

>And maybe we can share one instance of the EmptyNodeList
>for the whole dom tree so if a tree contains lots of empty node list we
>only allocate one.

I was thinking on this issue.

>The cast in getChildNode() isn't necessary since
>EmptyNodeList already is a NodeList.

I wrongly typed that.

Add to

import org.w3c.dom.NodeList;

   * Returns an EmptyNodeList.
  public NodeList getChildNodes()
    return EmptyNodeList.getInstance();

Add to gnu/xml/dom:

package gnu.xml.dom;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public final class EmptyNodeList implements NodeList

  private static EmptyNodeList instance = new EmptyNodeList();
  public static final EmptyNodeList getInstance() {return instance;}

  public EmptyNodeList () {}

  public final int getLength () {return 0;}

  public final Node item (int index) {return null;}


About the test case below:

I could not imagine a better class name. It needs a XML with DTD that contain 
all the elements that it tests. I need to learn about Mauve.

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;

public class Jxml {

public static final String version = "10/Jan/2006 03:45";

private static void checkNode (Node node) throws NullPointerException
  if (node==null) {throw new NullPointerException ("checkNode (Node) received 
a null Node.");}

  int nChilds = node.getChildNodes().getLength();

  if (
       (node instanceof CDATASection)||
       (node instanceof Comment)||
       (node instanceof DocumentType)||
       (node instanceof Notation)||
       (node instanceof ProcessingInstruction)||
       (node instanceof Text)
    if (nChilds>0)
      System.err.println (node.getClass().getName()+" extends 
"+node.getClass().getSuperclass().getName()+" does NOT 
implement .getChildNodes() correctly.");
      System.out.println (node.getClass().getName()+" is OK.");

private static void recurse (NodeList nl)
  for (int i=0; i<nl.getLength(); i++)

    Node node = nl.item (i);
    if (node==null) {continue;}

    checkNode (node);

  if (node instanceof DocumentType)
    DocumentType dt = (DocumentType) node;
    NamedNodeMap nnm = dt.getNotations();

    for (int j=0; j<nnm.getLength(); j++)

    NodeList nl2 = node.getChildNodes();
    int nChilds = nl2.getLength();
    if (nChilds>0) {recurse (nl2);}

public static void main (String [] args) {

System.out.println("getChildNodes() tester - version: "+version);

if (args.length==0) {System.out.print ("I need a xml file to parse.\n"); 

String fileName = args[0];

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (javax.xml.parsers.ParserConfigurationException pce) {

Document document = null;
try {
document = db.parse(fileName);
} catch (Exception e) {

recurse (document.getChildNodes());

}// Ends public static void main (String [] args) .

}// Ends public class Jxml .

reply via email to

[Prev in Thread] Current Thread [Next in Thread]