Commit a3504f9d by Patryk Czarnik

XPath waluty v2 z predykatem

parent 6893df37
......@@ -32,16 +32,13 @@ public class WalutyXPath2 {
System.out.println("Ewaluacja");
double suma = 0;
int ilosc = 0;
NodeList rates = (NodeList) xpath.evaluate("//Rate", doc, XPathConstants.NODESET);
NodeList rates = (NodeList) xpath.evaluate("//Rate[Code = '" + szukanyKod + "']", doc, XPathConstants.NODESET);
final int nRates = rates.getLength();
for (int i = 0; i < nRates; i++) {
Node rate = rates.item(i);
String code = xpath.evaluate("Code", rate);
if(code.equalsIgnoreCase(szukanyKod)) {
suma += (Double)xpath.evaluate("Mid", rate, XPathConstants.NUMBER);
ilosc++;
System.out.println(ilosc);
}
suma += (Double)xpath.evaluate("Mid", rate, XPathConstants.NUMBER);
ilosc++;
System.out.println(ilosc);
}
double srednia = suma / ilosc;
System.out.println("Średni kurs waluty " + szukanyKod + " = " + srednia);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment