[jdom-interest] Extending Element
Charles Havranek
havranekca at xde.net
Sat Aug 2 10:35:38 PDT 2003
Here's the class definition - can you give an example as the right way
to extend it ? :)
public class xdeElement extends org.jdom.Element{
public xdeElement() {
}
public static void main(String[] arg){
org.jdom.Element name = new org.jdom.Element("name");
name.setAttribute("language", "English");
xdeElement tmp= new xdeElement(name);
}
/** Create a new Element based on existing Element */
public xdeElement(org.jdom.Element existingElement){
super.setContent(existingElement.getContent());
System.out.println("Original: "+
existingElement.getAttributeValue("language"));
System.out.println("This: "+ this.getAttributeValue("language"));
System.out.println("Super: "+ super.getAttributeValue("language"));
}
Jason Hunter wrote:
> Attributes aren't returned in the getContent() call. Nor will you be
> copying the name, namespace, and other features like that. The
> standard way to extend Element is to "extends Element". Then you
> don't have to worry about copying things, just extending.
>
> -jh-
>
> Charles Havranek wrote:
>
>> Been searching the archives and can't find a good answer or example
>> for extending an element to add my own helper methods. Trying :
>> public xdeElement() {
>> }
>> public static void main(String[] arg){
>> org.jdom.Element name = new org.jdom.Element("name");
>> name.setAttribute("language", "English");
>> xdeElement tmp= new xdeElement(name);
>> }
>> /** Create a new Element based on existing Element */
>> public xdeElement(Element existingElement){
>> super.setContent(existingElement.getContent());
>> System.out.println("Original: "+
>> existingElement.getAttributeValue("language"));
>> System.out.println("This: "+ this.getAttributeValue("language"));
>> System.out.println("Super: "+
>> super.getAttributeValue("language"));
>> }
>>
>> when run, it Outputs :
>> Original: English
>> This: null
>> Super: null
>>
>> Sure I'm doing something wrong ... but what?
>>
>> Thanks much!
>> Charles Havranek
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
>>
>>
>
>
More information about the jdom-interest
mailing list