We help IT Professionals succeed at work.

do we need document object to use xpath

gudii9
gudii9 asked
on
159 Views
Last Modified: 2014-08-04
Hi,

I am reading as below

create document object as below.


Document document = builder.parse(
new FileInputStream("c:\\customers.xml"));



then use XPath by creating an xpath object using XPathFactory.
Reading names of all customers
String expression = "/Customers/Customer/firstname";
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);


do we need document object to use xpath?
please advise
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
do we need document object to use xpath?
please advise
Yes. XPath works by inspecting a DOM

Author

Commented:
does XPath do not work with SAX(works only DOM). Please advise
CERTIFIED EXPERT
Top Expert 2016

Commented:
Yes, only with DOM

Author

Commented:
why does xpath inspect DOM in between. why does xpath inspect XML directly?
Please advice
CERTIFIED EXPERT
Top Expert 2016

Commented:
What do you mean by 'in between'?

Author

Commented:
Document document = builder.parse(
new FileInputStream("c:\\customers.xml"));

I mean above step is extra in between step right(i.e building DOM from the XML) Please advise
CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.