cbr_daily.xml
<ValCurs Date="30/05/2009" name="Foreign Currency Market">
<Valute ID="R01035">
<NumCode>826</NumCode>
<CharCode>GBP</CharCode>
<Nominal>1</Nominal>
<Name>Фунт стерлингов Соединенного королевства</Name>
<Value>49,7887</Value>
</Valute>
<Valute ID="R01235">
<NumCode>840</NumCode>
<CharCode>USD</CharCode>
<Nominal>1</Nominal>
<Name>Доллар США</Name>
<Value>30,9843</Value>
</Valute>
<Valute ID="R01239">
<NumCode>978</NumCode>
<CharCode>EUR</CharCode>
<Nominal>1</Nominal>
<Name>Евро</Name>
<Value>43,3780</Value>
</Valute>
</ValCurs>
ValCursType.java
package xqx;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "ValCurs")
@XmlType(name = "ValCursType")
public class ValCursType {
@XmlElement(name = "Valute")
public List<ValuteType> valuteType;
@XmlAttribute(name = "Date")
public String date;
@XmlAttribute
public String name;
}
ValuteType.java
package xqx;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "Valute")
@XmlType(name = "ValuteType")
public class ValuteType {
@XmlElement(name = "NumCode")
public String numCode;
@XmlElement(name = "CharCode")
public String charCode;
@XmlElement(name = "Nominal")
public int nominal;
@XmlElement(name = "Name")
public String name;
@XmlElement(name = "Value")
public String value;
@XmlAttribute(name = "ID")
public String id;
}
CbrCurrencyTask.java
package xqx;
import ...;
public class CbrCurrencyTask {
...
//stream - For example FileInputStream created from the "cbr_daily.xml" file
protected ValCursType parse(InputStream stream) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(ValCursType.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
ValCursType valCursType = (ValCursType) unmarshaller.unmarshal(stream);
return valCursType;
}
...
}
Simple! Isn't it?
No comments:
Post a Comment