Answer the question
In order to leave comments, you need to log in
How to parse certain elements from an XML file?
There is a specific xml file with the following structure:
<ValCurs>
<Valute ID="R01010">
<NumCode>036</NumCode>
<CharCode>AUD</CharCode>
<Nominal>1</Nominal>
<Name>Австралийский доллар</Name>
<Value>44,1039</Value>
</Valute>
<Valute ID="R01020A">
<NumCode>944</NumCode>
<CharCode>AZN</CharCode>
<Nominal>1</Nominal>
<Name>Азербайджанский манат</Name>
<Value>33,5431</Value>
</Valute>
<Valute ID="R01035">
<NumCode>826</NumCode>
<CharCode>GBP</CharCode>
<Nominal>1</Nominal>
<Name>Фунт стерлингов Соединенного королевства</Name>
<Value>80,6068</Value>
</Valute>
</ValCurs>
private void pullDataInArticles(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
int eventType = xmlPullParser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && xmlPullParser.getName().equalsIgnoreCase("Valuet")) {
if (xmlPullParser.getName().equalsIgnoreCase("Value") && xmlPullParser.getAttributeValue(0).equals("R01235")) {
String title = xmlPullParser.getText();
currentArticle.setTitle_usd(title);
Log.d("valueXML",title);
} else if (xmlPullParser.getName().equalsIgnoreCase("Value") && xmlPullParser.getAttributeValue(0).equals("R01239")){
String title = xmlPullParser.getText();
currentArticle.setTitle_euro(title);
Log.d("valueXML",title);
} else if (eventType == XmlPullParser.END_TAG && xmlPullParser.getName().equalsIgnoreCase("Valuet")) {
articles.add(currentArticle);
currentArticle = new Article();
}
eventType = xmlPullParser.next();
}
triggerObserver();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question