0
나는 pull-parsing을 사용하여 로컬 XML의 특정 부분을 파싱하려고하는데, 어떻게 읽었는지 모르겠습니다. 나는 코드를 사용하고 있습니다 : 나는 시간에 아야에있는 하나의 텍스트 문자열에 액세스하려고 해요 :안드로이드에서 로컬 XML 파일 구문 분석하기
package com.example.xmltest;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView myXmlContent = (TextView)findViewById(R.id.xml_tv);
String stringXmlContent;
stringXmlContent = getAllXML();
myXmlContent.setText(stringXmlContent);
}
public String getAllXML(){
Activity activity = this;
String str = "";
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.ensaheehint);
try {
xpp.next();
int eventType = xpp.getEventType();
System.out.println("eventType : " + eventType);
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.START_DOCUMENT){
str += "nXML Parsing Starting...n";
}
else if(eventType == XmlPullParser.START_TAG)
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT){
String text = xpp.getName();
str += "**TEXT: "+text;
}
}
else if(eventType == XmlPullParser.END_TAG)
{
str += "nending tag: "+xpp.getName();
}
else if(eventType == XmlPullParser.TEXT)
{
str += "nvalue : "+xpp.getText();
}
eventType = xpp.next();
}
str += "nnXML parsing Ending......";
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
는 아래처럼 내 XML 파일의 모습입니다.
<quran>
<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, the Entirely Merciful, the Especially Merciful."/>
<aya index="2" text="[All] praise is [due] to Allah, Lord of the worlds -"/>
<aya index="3" text="The Entirely Merciful, the Especially Merciful,"/>
<aya index="4" text="Sovereign of the Day of Recompense."/>
<aya index="5" text="It is You we worship and You we ask for help."/>
<aya index="6" text="Guide us to the straight path -"/>
<aya index="7" text="The path of those upon whom You have bestowed favor, not of those who have evoked [Your] anger or of those who are astray."/>
</sura>
각 아야마다 ** 텍스트 속성 **을 읽어야한다고 생각하는 것이 맞지만 검색과 같은 방식으로이 작업을 수행해야합니다. 예를 들어 사용자가 2:34를 입력하면 index 속성이 34 인 aya의 텍스트 속성에서 두 번째 sura에있는 문자열이 반환된다는 것을 의미합니다. –
아하, 이제 알았어. 수라 노드에 대한 색인 속성을 확인합니다 (2). 아야 노드 중 25 개에 대한 색인 속성을 검색합니다. 나는 그것이 오히려 솔직해야한다고 생각합니다. 당신은 건설 할 기초가 좋은 것 같습니다. 내가 놓친 게 아니라면. :-) – Qben
고마워, 잠시 동안 미안해! –