The Document Object Model (DOM) is a cross-
platform and language-independent convention for
representing and interacting with objects in HTML,
XHTML and XML documents. Objects in the DOM
tree may be addressed and manipulated by using
methods on the objects.
Ex: var element=document.getElementById("intro");
XPath, the XML Path Language, is a query language
for selecting nodes from an XML document. In
addition, XPath may be used to compute values
(e.g., strings, numbers, or Boolean values) from the
content of an XML document.
They are complementary rather than competing. DOM provides a tree model of XML with low-level navigation capability (get first child, get next sibling, etc); XPath adds a much higher-level search and navigation capability
Note also that DOM is just one tree model for XML, and is very far from being the best: it's the first and the worst, and it's a shame that so many people still use it. In the Java world there are much better designs available such as JDOM and XOM.
But as starter I will remember DOM as the database and xpath is the SQL query.
Absolute Xpath :
1) start selection from the document node
2) Starts with //
3) e.g. “/html/body/p” matches all the paragraph elements
Google Search Box : /html/body/div/div/div/div/div/div/div/div/form/fieldset/div/div/div
Relative Xpath :
1) start selection matching anywhere in the document
2) Starts with /
3) e.g. “//p” matches all the paragraph elements starts with p
Google Search Box : //*[@id='gbqfqwb']