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);
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?
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?
The use of the document is as follow:
These tree steps will fix your problem.
DocumentBuilder
returns some implementation ofDocument
. You don't have to worry about implementing theDocument
interface, somebody has already done that for you. The returned document will represent the XML document, which is what you want.