I am working on xml in my android project and I am a beginner. i have a same xml in different language too like that
<sura index="1" name="الفاتحة">
<aya index="1" text="الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ" bismillah="بِسْمِ اللَّهِ الرَّحْمَنِ
الرَّحِيمِ" />
<aya index="2" text="الرَّحْمَنِ الرَّحِيمِ" />
<aya index="3" text="مَالِكِ يَوْمِ الدِّينِ" />
<aya index="4" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />
<aya index="5" text="اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ" />
<aya index="6" text="صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ" />
</sura>
this one is in arabic
<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, most benevolent, ever-merciful."/>
<aya index="2" text="ALL PRAISE BE to Allah, Lord of all the worlds,"/>
<aya index="3" text="Most beneficent, ever-merciful,"/>
<aya index="4" text="King of the Day of Judgement."/>
<aya index="5" text="You alone we worship, and to You alone turn for help."/>
<aya index="6" text="Guide us (O Lord) to the path that is straight,"/>
<aya index="7" text="The path of those You have blessed, Not of those who have earned Your anger, nor those who have gone astray."/>
</sura>
this one in english.
I have successfully done parsing for aya in arabic using this code
private List<String> getAllAyaFromSuraIndex(String suraIndex) throws XmlPullParserException, IOException {
list = new ArrayList<>();
XmlPullParser parser = getResources().getXml(R.xml.quran_arabic);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("sura")) {
String index = parser.getAttributeValue(0);
// Match given sure index
if (index.equals(suraIndex)) {
// Move to first aya tag inside matched sura index
parser.next();
// This loop will exit when it reaches sura end tag </sura>
while (parser.getName().equals("aya")) {
if (parser.getEventType() == XmlPullParser.START_TAG) {
list.add(parser.getAttributeValue(null,"index") + ".\n" + parser.getAttributeValue(null,"text"));
}
// Move to next aya tag
parser.next();
}
break;
}
}
parser.next();
}
return list;
}
I have a listview with two textviews one for arabic and one for english. I tried everything but not getting the results.