Quote:
Originariamente inviato da dupa
Facendo così ora sembra andare:
Codice PHP:
File xmlDocument = new File("c:/test.xml");
InputSource inputSource;
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
try {
inputSource = new InputSource(new FileInputStream(xmlDocument));
replication = Integer.parseInt(xPath.evaluate("/simulator/setup/replication", inputSource));
System.out.println(replication);
inputSource = new InputSource(new FileInputStream(xmlDocument));
warmuptime = Integer.parseInt(xPath.evaluate("/simulator/setup/warmuptime", inputSource));
System.out.println(warmuptime);
in pratica continuo a ricaricare inputSource.
sicuramente non è la soluzione giusta al problema, per ora però mi accontento, se hai idee migliori son benvenute 
|
Dalle API del java 1.5:
Codice:
// parse the XML as a W3C Document
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.Document document = builder.parse(new File("/widgets.xml"));
// evaluate the XPath expression against the Document
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget[@name='a']/@quantity";
Double quantity = (Double) xpath.evaluate(expression, document, XPathConstants.NUMBER);