Skip to Content
0

DOM Parser method

Apr 12, 2017 at 03:43 PM

41

avatar image

Hi SDNites,

I am trying to implement a JAVA mapping using DOM parser and have a query around using methods getElementsByTagName. Below is the code snippet,

dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nodeList = doc.getElementsByTagName("Employee");


As getElementsByTagName is method of interface Element while in the above Document class instance doc is trying to access the method and is working. Can you please let me know why it is allowed to access this method from a Document class which does not have this method.

Regards,

Abhi

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Evgeniy Kolmakov Apr 12, 2017 at 05:32 PM
0

Hi Abhi!

First, Document is an interface too, not a class. It extends Node interface.

Second, why not to have methods with the same name for different interfaces?

Interface Document has its own getElementByTagName() method.

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded