Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

do we need document object to use xpath?
please advise
Yes. XPath works by inspecting a DOM
Avatar of gudii9

ASKER

does XPath do not work with SAX(works only DOM). Please advise
Yes, only with DOM
Avatar of gudii9

ASKER

why does xpath inspect DOM in between. why does xpath inspect XML directly?
Please advice
What do you mean by 'in between'?
Avatar of gudii9

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial