Java XPath: Get all the elements that match a query

xExTreMex

New Member
I want to make an XPath query on this XML file (excerpt shown):\[code\]<?xml version="1.0" encoding="UTF-8"?><!-- MetaDataAPI generated on: Friday, May 25, 2007 3:26:31 PM CEST --><Component xmlns="http://xml.sap.com/2002/10/metamodel/webdynpro" xmlns:IDX="urn:sap.com:WebDynpro.Component:2.0" mmRelease="6.30" mmVersion="2.0" mmTimestamp="1180099591892" name="MassimaleContr" package="com.bi.massimalecontr" masterLanguage="it">... <Component.UsedModels> <Core.Reference package="com.test.test" name="MasterModel" type="Model"/> <Core.Reference package="com.test.massimalecontr" name="MassimaleModel" type="Model"/> <Core.Reference package="com.test.test" name="TravelModel" type="Model"/> </Component.UsedModels>...\[/code\]I'm using this snippet of code:\[code\]DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();domFactory.setNamespaceAware(true);DocumentBuilder builder = domFactory.newDocumentBuilder();Document document = builder.parse(new File("E:\\Test branch\\test.wdcomponent"));XPathFactory factory = XPathFactory.newInstance();XPath xpath = factory.newXPath();xpath.setNamespaceContext(new NamespaceContext() {...(omitted)System.out.println(xpath.evaluate( "//d:Component/d:Component.UsedModels/d:Core.Reference/@name", document));\[/code\]What I'm expecting to get:\[code\]MasterModelMassimaleModelTravelModel\[/code\]What I'm getting:\[code\]MasterModel\[/code\]It seems that only the first element is returned. How can I get all the occurrences that matches my query?
 
Back
Top