You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Wayne Johnson <wd...@yahoo.com> on 2004/03/04 22:03:52 UTC

Extending (subclassing) Elements

This might be more of a Java question, but I'll ask it here anyway since
our Java gurus don't have an answer...

I would like to subclass Elements.  Now I know an Element is really an
interface, not a class.  How do I go about extending the Elements
interface so that I can add some customized methods to it?

Do I have to subclass the ElementImpl?  When I try this, and then attempt
to cast the Element returned by getDocumentElement to my subclass, I get
a java.lang.ClassCastException.

Anyone have any suggestions?

Thanks in advance.

=====
---
Wayne Johnson,             | There are two kinds of people: Those 
3943 Penn Ave. N.          | who say to God, "Thy will be done," 
Minneapolis, MN 55412-1908 | and those to whom God says, "All right, 
(612) 522-7003             | then,  have it your way." --C.S. Lewis

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Extending (subclassing) Elements

Posted by Michael Glavassevich <mr...@apache.org>.
Hi Wayne,

The Document is the node factory. Have a look at the
http://apache.org/xml/properties/dom/document-class-name property.

On Thu, 4 Mar 2004, Wayne Johnson wrote:

> Thanks for the response.
>
> I think I understand everything but "set the document factory on the
> DOMParser".  I looked at the properties page
> (http://xml.apache.org/xerces2-j/properties.html?) and dont see anything
> about setting the document factories.
>
> Thanks.
>
> --- Andy Clark <an...@apache.org> wrote:
> > Wayne Johnson wrote:
> > > Do I have to subclass the ElementImpl?  When I try this, and then
> > attempt
> > > to cast the Element returned by getDocumentElement to my subclass, I
> > get
> > > a java.lang.ClassCastException.
> >
> > Subclass both ElementImpl and DocumentImpl. You have to
> > change the factory so that it returns your element types
> > from createElement and createElementNS.
> >
> > Once you do that, you can set the document factory on
> > the DOMParser. Check the properties page in the docs for
> > information.
> >
> > --
> > Andy Clark * andyc@apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
>
>
> =====
> ---
> Wayne Johnson,             | There are two kinds of people: Those
> 3943 Penn Ave. N.          | who say to God, "Thy will be done,"
> Minneapolis, MN 55412-1908 | and those to whom God says, "All right,
> (612) 522-7003             | then,  have it your way." --C.S. Lewis
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Search - Find what you�re looking for faster
> http://search.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>

-- 
---------------------------
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Extending (subclassing) Elements

Posted by Wayne Johnson <wd...@yahoo.com>.
Thanks for the response.

I think I understand everything but "set the document factory on the
DOMParser".  I looked at the properties page
(http://xml.apache.org/xerces2-j/properties.html?) and dont see anything
about setting the document factories.

Thanks.

--- Andy Clark <an...@apache.org> wrote:
> Wayne Johnson wrote:
> > Do I have to subclass the ElementImpl?  When I try this, and then
> attempt
> > to cast the Element returned by getDocumentElement to my subclass, I
> get
> > a java.lang.ClassCastException.
> 
> Subclass both ElementImpl and DocumentImpl. You have to
> change the factory so that it returns your element types
> from createElement and createElementNS.
> 
> Once you do that, you can set the document factory on
> the DOMParser. Check the properties page in the docs for
> information.
> 
> -- 
> Andy Clark * andyc@apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 


=====
---
Wayne Johnson,             | There are two kinds of people: Those 
3943 Penn Ave. N.          | who say to God, "Thy will be done," 
Minneapolis, MN 55412-1908 | and those to whom God says, "All right, 
(612) 522-7003             | then,  have it your way." --C.S. Lewis

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Extending (subclassing) Elements

Posted by Andy Clark <an...@apache.org>.
Wayne Johnson wrote:
> Do I have to subclass the ElementImpl?  When I try this, and then attempt
> to cast the Element returned by getDocumentElement to my subclass, I get
> a java.lang.ClassCastException.

Subclass both ElementImpl and DocumentImpl. You have to
change the factory so that it returns your element types
from createElement and createElementNS.

Once you do that, you can set the document factory on
the DOMParser. Check the properties page in the docs for
information.

-- 
Andy Clark * andyc@apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org