在Java中的Document接口上调用方法 [英] Calling method on Document interface in Java
问题描述
我正在尝试用Java解析XML文件,在获得 DocumentBuilder
对象后,我调用它上面的parse方法来获取文档
对象。
,例如文档dom = docbuild.parse(fileName);
I am trying to parse an XML file in Java and after getting the DocumentBuilder
object, I call the parse method on it to get a Document
object.
e.g. Document dom = docbuild.parse(fileName);
然后为了获取XML文件的根目录,我使用方法 dom.getDocumentElement();
。
由于文档
是javadocs中定义的接口,我们如何在不先定义它的情况下调用它上面的方法?
Then to get the root of the XML file, I use the method dom.getDocumentElement();
.
Since Document
is an interface as defined in the javadocs, how are we able to call a method on it without defining it first?
我的主要目标是创建一个继承Document接口的类,所以我必须实现它。我该怎么做呢?
My main objective is to create a class that inherits the Document interface, so I have to implement it. How do I go about doing this?
推荐答案
DocumentBuilder
返回文档的一些实现
。你不必担心实现 Document
界面,有人已经为你做了这个。返回的文档将代表XML文档,这就是您想要的。
DocumentBuilder
returns some implementation of Document
. You don't have to worry about implementing the Document
interface, somebody has already done that for you. The returned document will represent the XML document, which is what you want.
这篇关于在Java中的Document接口上调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!