users@jaxb.java.net

Re: Marshalling a content sub-tree

From: François Banel <fbanel_at_LAPOSTE.NET>
Date: Fri, 28 Mar 2003 03:38:22 -0700

Hello,

I have written a possible implementation of the ElementWrapper
For me it works fine, but I have a question.
If I know that the ElementWrapper I want to create must have the
same namespace as the wrapped JAXB object, I would like not
to have to precise the namespace. Can it be retrieved from the
wrapped JAXB object ?




Element wrapper code :

import javax.xml.bind.*;
import com.sun.xml.bind.serializer.XMLSerializable;

public class ElementWrapper
implements
 com.sun.xml.bind.serializer.XMLSerializable
 {

 private XMLSerializable _element = null;
 private String _namespace = null;
 private String _localName = null;

 public ElementWrapper(String namespace, String localName, Object element) {
  this._element = (XMLSerializable)element;
     this._namespace = namespace;
  this._localName = localName;
 }

    public void serializeElements(com.sun.xml.bind.serializer.XMLSerializer context)
        throws org.xml.sax.SAXException
    {
  context.startElement(_namespace, _localName);
        _element.serializeAttributes(context);
        context.endAttributes();
        _element.serializeElements(context);
        context.endElement();
    }

    public void serializeAttributes(com.sun.xml.bind.serializer.XMLSerializer context)
        throws org.xml.sax.SAXException
    {
    }

    public void serializeAttributeBodies(com.sun.xml.bind.serializer.XMLSerializer context)
        throws org.xml.sax.SAXException
    {
    }

}