Commit a3504f9d by Patryk Czarnik

XPath waluty v2 z predykatem

parent 6893df37
...@@ -32,16 +32,13 @@ public class WalutyXPath2 { ...@@ -32,16 +32,13 @@ public class WalutyXPath2 {
System.out.println("Ewaluacja"); System.out.println("Ewaluacja");
double suma = 0; double suma = 0;
int ilosc = 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(); final int nRates = rates.getLength();
for (int i = 0; i < nRates; i++) { for (int i = 0; i < nRates; i++) {
Node rate = rates.item(i); Node rate = rates.item(i);
String code = xpath.evaluate("Code", rate); suma += (Double)xpath.evaluate("Mid", rate, XPathConstants.NUMBER);
if(code.equalsIgnoreCase(szukanyKod)) { ilosc++;
suma += (Double)xpath.evaluate("Mid", rate, XPathConstants.NUMBER); System.out.println(ilosc);
ilosc++;
System.out.println(ilosc);
}
} }
double srednia = suma / ilosc; double srednia = suma / ilosc;
System.out.println("Średni kurs waluty " + szukanyKod + " = " + srednia); 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