jquery - How parsing xml from url get attribute javascript -
i need parsing xml url url xml
<?xml version="1.0" encoding="utf-8"?> <exchangerates> <row> <exchangerate ccy="rur" base_ccy="uah" buy="0.33291" sale="0.33291"/> </row> <row> <exchangerate ccy="eur" base_ccy="uah" buy="18.60253" sale="18.60253"/> </row> <row> <exchangerate ccy="usd" base_ccy="uah" buy="14.97306" sale="14.97306"/> </row> </exchangerates>
i whant attribute using "14.97306" convert currency
(like mycurrency = 10 ) (like usd = 14.97306 ) (mycurrency * usd = 149.7306)
here's rudimentary setup java. you'll need read on xpath queries, , need add exception handling etc. i'm sure started.
// open url url url = .... inputstream = url.openstream(); // build document parser documentbuilderfactory domfactory = documentbuilderfactory.newinstance(); domfactory.setnamespaceaware(true); documentbuilder builder = domfactory.newdocumentbuilder(); // parse document url document d = builder.parse(is); // set xpath examine/query xml xpathfactory factory = xpathfactory.newinstance(); xpath xpath = factory.newxpath(); // use xpath query find required information string sale = xpath.evaluate("/exchangerates/row[@ccy='usd']/@sale", d); system.out.println("usd sale "+sale);
Comments
Post a Comment