开发者

Why can we call methods of interface org.w3c.dom.Document?

I don't see any class implementing th开发者_JS百科e methods of interface org.w3c.dom.Document. Then why can we (usually) call getDocumentElement method of this interface to get the root element ?


org.w3c.dom.Document is a part of XML specifications which can be implemented by many different libraries. If you want to know which exact implementation is used, try

org.w3c.dom.Document doc = <your instance>;   
System.out.println(doc.getClass().getName());

at the same place where you call methods on it. That will tell you the name of implementing class that would have those methods (or its superclass would).


The org.w3c.dom package and it's classes is part of the Java API for XML Processing (JAXP). It is present to provide the Java language binding for the DOM Level 2 Core API.

The language binding merely exists to provide an interface that can be implemented by various DOM parsers. After all, different parsers will have different techniques to maintain the internal data structures that represent the DOM. Multiple JAXP parsers that comply with the DOM Core API can co-exist in the libraries available to the JVM. At runtime, only one of these will be utilized for parsing XML documents.

You can call the method, once a suitable DOM parser that implements JAXP, has read the contents of an XML document, and has populated it's internal structures to make an instance of the Document class available to you. In other words, the DOM parser is responsible for providing you with an instance of the Document object, after parsing a XML document.


Few of the known implementations are Xerces and JDom

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜