cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <sylvain.wal...@anyware-tech.com>
Subject Re: toDOM and toSAX of XMLFragment
Date Tue, 23 Jan 2001 14:50:46 GMT


Ulrich Mayring a écrit :
> 
> Hello,
> 
> how are the implementations of the toDOM and toSAX methods supposed to
> look like? I see that they receive a Node or a ContentHandler
> respectively and return nothing - what are they supposed to do?
> 
> Ulrich
> 
> --
> Ulrich Mayring
> DENIC eG, Systementwicklung
> 

An XMLFragment is an object that can be represented as a XML document
fragment. The toDOM() method (used by C1) should append the XML
representation of the object as children of the given node, and the
toSAX() method (used by C2) should generate the XML representation as
SAX events.

A typical XMLFragment implementation could look like this :

  public class FragmentTest implements XMLFragment
  {
    public void toDOM(Node node)
    {
      Document doc = node.getOwnerDocument();
      Element e = doc.createElement("foo");
      e.appendChild(doc.createTextNode("bar"));
      node.appendChild(e);
    }

    public void toSAX(ContentHandler handler)
    {
      AttributesImpl attr = new AttributesImpl();
      handler.startElement("","foo","foo",attr);

      String content = "bar";
      handler.characters(content.toCharArray(), 0, content.length());

      handler.endElement("","foo","foo");
    }
  }

Both methods result in <foo>bar</foo> to be inserted in the resulting
document.

Hope this helps.
-- 
Sylvain Wallez
Anyware Technologies

Mime
View raw message