[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

do we need document object to use xpath

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
0
gudii9
Asked:
gudii9
  • 4
  • 3
1 Solution
 
CEHJCommented:
do we need document object to use xpath?
please advise
Yes. XPath works by inspecting a DOM
0
 
gudii9Author Commented:
does XPath do not work with SAX(works only DOM). Please advise
0
 
CEHJCommented:
Yes, only with DOM
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gudii9Author Commented:
why does xpath inspect DOM in between. why does xpath inspect XML directly?
Please advice
0
 
CEHJCommented:
What do you mean by 'in between'?
0
 
gudii9Author 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
0
 
CEHJCommented:
Well, we've just established that you need a DOM so if you haven't got one, then i don't see why taking all necessary steps to create one is in any way surprising ..?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now