cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Torsten Curdt" <tcu...@dff.st>
Subject RE: XObject
Date Fri, 01 Dec 2000 21:34:00 GMT
Ok, lets say there an XObject interface
*somewhere* ;) in the codebase.

This *was* the old one:

  import org.w3c.dom.Node;
  import org.xml.sax.DocumentHandler;

  public interface XObject {
    public void toSAX(DocumentHandler handler);
    public void toDOM(Node node);
  }

And if got it right the new one could
look similiar to this:

  import org.w3c.dom.Node;
  import org.xml.sax.ContentHandler;

  public interface XObject {
    public void toSAX(ContentHandler handler);
    public void toDOM(Node node);
  }

I was wondering how an implementation might
look like. Maybe something like this?

  public class test implements XObject{
    public void toDOM(Node node){
	Document doc = node.getOwnerDocument();
	Element e = doc.createElement("test");
	e.appendChild(doc.createTextNode("content"));
      node.appendChild(e);
    }

    public void toSAX(ContentHandler handler){
      AttributesImpl attr = new AttributesImpl();
	String content = "content";

      handler.startElement("","test","test",attr);
	attr.clear();

      handler.characters(content.toCharArray(), 0, content.length());

      handler.endElement("","test","test",attr);
	}
  }

toSAX and toDOM should both give:

  <test>content</test>

Correct!? (Haven't tested yet)
--
Torsten

Mime
View raw message