添加方法org.w3c.dom.Node中 [英] add methods to org.w3c.dom.Node

查看:691
本文介绍了添加方法org.w3c.dom.Node中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加自定义的方法Node类,但最终创建一个变量保存一个节点对象的新类。

因此​​问题。是它甚至可能吗?

我这样做:

 公共类旅行实现org.w3c.dom.Node中的{
    [...生成的方法...]
    公共字符串myMethod的(){
        返回;
    }
}

但我获得了大量的错误,所以我结束了做这个

 公共类旅行{
    私人节点了mnode;
    公共无效之旅(节点tripNode){
            this.mNode = tripNode;
    }
    公共字符串myMethod的(){
        返回;
    }
}


解决方案

org.w3c.dom.Node中是一个接口,因此你贴code将无法工作。

您不想开始尝试实现自己的DOM,所以我建议你认为一个不同的方法。什么是你想干什么?

您也许可以利用get和<一个href=\"http://download.oracle.com/javase/6/docs/api/org/w3c/dom/Node.html#setUserData%28java.lang.String,%20java.lang.Object,%20org.w3c.dom.UserDataHandler%29\"相对=nofollow> setUserData来来达成你的目标。

I tried adding a custom method to the Node class but ended up creating a new class that holds a node object in a variable.

so the question is. is it even possible?

I did this:

public class Trip implements org.w3c.dom.Node { 
    [...generated methods...] 
    public String myMethod(){
        return "";
    }
}

but I was getting lots of errors so I ended up doing this

public class Trip { 
    private Node mNode;
    public void Trip(Node tripNode){
            this.mNode = tripNode;
    }
    public String myMethod(){
        return "";
    }
}

解决方案

org.w3c.dom.Node is an interface, therefore your posted code won't work.

You don't want to start trying to implement your own DOM, so I suggest you think of a different approach. What is it you want to do?

You might be able to make use of get and setUserData to accomplish your goal.

这篇关于添加方法org.w3c.dom.Node中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆