Android 如何在xml解析中解析属性中的值
嗨,我有一个这样的网络服务Android 如何在xml解析中解析属性中的值,android,xml,parsing,listview,Android,Xml,Parsing,Listview,嗨,我有一个这样的网络服务 <audio title="Terry Waychuk Pure2010" audio="http://www.boodang.com/api/audio/**Terry_Waychuk**/Terry_Waychuk_Pure2010.mp3" description="Terry Waychuk Pure2010" createddate = "23-01-2011" thumbnail="http://www.boodang.com/api/thumb/b
<audio title="Terry Waychuk Pure2010" audio="http://www.boodang.com/api/audio/**Terry_Waychuk**/Terry_Waychuk_Pure2010.mp3" description="Terry Waychuk Pure2010" createddate = "23-01-2011" thumbnail="http://www.boodang.com/api/thumb/boodean_logo.png" />
<audio title="Terry Waychuk frequency2010" audio="http://www.boodang.com/api/audio/**Terry_Waychuk**/Terry_Waychuk_frequency2010.mp3" description="Terry Waychuk frequency2010" createddate = "23-01-2011" thumbnail="http://www.boodang.com/api/thumb/boodean_logo.png" />
<audio title="The Grimey Tech RandomHero FlooRLayer Scooty OH Mazik Boodang 10 Year Anniversary Promo Mix" audio="http://www.boodang.com/api/audio/**The_Grimey_Tech**/The_Grimey_Tech_RandomHero_FlooRLayer_Scooty_OH_Mazik_Boodang_10_Year_Anniversary_Promo_Mix.mp3" description="The Grimey Tech RandomHero FlooRLayer Scooty OH Mazik Boodang 10 Year Anniversary Promo Mix" createddate = "23-01-2011" thumbnail="http://www.boodang.com/api/thumb/boodean_logo.png" />
<audio title="The Grimey Tech and Titus 1 Warper Warfare" audio="http://www.boodang.com/api/audio/**The_Grimey_Tech**/The_Grimey_Tech_and_Titus_1_Warper_Warfare.mp3" description="The Grimey Tech and Titus 1 Warper Warfare" createddate = "23-01-2011" thumbnail="http://www.boodang.com/api/thumb/boodean_logo.png" />
.
.
.
.
.
单击其中任何一个后,将列表视图显示为mp3文件标题(前两个是Terry_Waychuk,后两个是Grimey_Tech)。因此,请告诉我如何在属性值中获取特定名称,以及如何将特定mp3文件添加到该文件夹(Terry_Waychuk或the_Grimey_Tech)。使用android
XmlPullParser的单向(您没有指定使用哪一个)是在收到XmlPullParser.START_标记时将属性拉入映射中,因此,假设主解析::
private void parseContent(XmlPullParser parser)
throws XmlPullParserException,IOException,Exception {
int eventType;
while((eventType=parser.next()) != XmlPullParser.END_TAG) {
if (eventType == XmlPullParser.START_TAG) {
Log.d(MY_DEBUG_TAG,"Parsing Attributes for ["+parser.getName()+"]");
Map<String,String> attributes = getAttributes(parser);
}
else if(eventType==...);
else {
throw new Exception("Invalid tag at content parse");
}
}
}
private Map<String,String> getAttributes(XmlPullParser parser) throws Exception {
Map<String,String> attrs=null;
int acount=parser.getAttributeCount();
if(acount != -1) {
Log.d(MY_DEBUG_TAG,"Attributes for ["+parser.getName()+"]");
attrs = new HashMap<String,String>(acount);
for(int x=0;x<acount;x++) {
Log.d(MY_DEBUG_TAG,"\t["+parser.getAttributeName(x)+"]=" +
"["+parser.getAttributeValue(x)+"]");
attrs.put(parser.getAttributeName(x), parser.getAttributeValue(x));
}
}
else {
throw new Exception("Required entity attributes missing");
}
return attrs;
}
private void parseContent(XmlPullParser)
抛出XmlPullParserException、IOException、Exception{
int事件类型;
while((eventType=parser.next())!=XmlPullParser.END_标记){
if(eventType==XmlPullParser.START_标记){
Log.d(MY_DEBUG_标记,“解析[“+parser.getName()+”]”的属性);
Map attributes=getAttributes(解析器);
}
else if(eventType==…);
否则{
抛出新异常(“内容解析时标记无效”);
}
}
}
私有映射getAttributes(XmlPullParser)引发异常{
Map attrs=null;
int acount=parser.getAttributeCount();
如果(acount!=-1){
Log.d(MY_DEBUG_标记,[“+parser.getName()+”]”的属性);
attrs=新哈希映射(acount);
对于(int x=0;x)如何使用XMLPullparser获取
private void parseContent(XmlPullParser parser)
throws XmlPullParserException,IOException,Exception {
int eventType;
while((eventType=parser.next()) != XmlPullParser.END_TAG) {
if (eventType == XmlPullParser.START_TAG) {
Log.d(MY_DEBUG_TAG,"Parsing Attributes for ["+parser.getName()+"]");
Map<String,String> attributes = getAttributes(parser);
}
else if(eventType==...);
else {
throw new Exception("Invalid tag at content parse");
}
}
}
private Map<String,String> getAttributes(XmlPullParser parser) throws Exception {
Map<String,String> attrs=null;
int acount=parser.getAttributeCount();
if(acount != -1) {
Log.d(MY_DEBUG_TAG,"Attributes for ["+parser.getName()+"]");
attrs = new HashMap<String,String>(acount);
for(int x=0;x<acount;x++) {
Log.d(MY_DEBUG_TAG,"\t["+parser.getAttributeName(x)+"]=" +
"["+parser.getAttributeValue(x)+"]");
attrs.put(parser.getAttributeName(x), parser.getAttributeValue(x));
}
}
else {
throw new Exception("Required entity attributes missing");
}
return attrs;
}