本文介紹了如何在java中將xml標(biāo)簽存儲(chǔ)為數(shù)組的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
在我的應(yīng)用程序中,我正在解析一個(gè) xml 文件.在 xml 文件中,我有 50 個(gè)同名的標(biāo)簽 question
,現(xiàn)在我想將所有名為 question 的標(biāo)簽存儲(chǔ)為一個(gè)數(shù)組....
in my app i am parsing an xml file. In the xml file i am having 50 tags of the same name question
, now i want to store all the tag named as question as an array....
在保存的這些標(biāo)簽中,我只想將一個(gè)問(wèn)題標(biāo)簽放置在文本視圖中......
Among those tags saved i want only one question tag to be placed in a text view....
如何執(zhí)行此操作....請(qǐng)幫助我.....
how to perform this....pls help me.....
推薦答案
public class CustomHandler extends DefaultHandler {
private ArrayList<String> questionList;
private boolean questionBuffering;
private StringBuilder sb;
@Override
public void startDocument() throws SAXException {
questionList = new ArrayList<String>();
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (localName.equals("question")) {
questionBuffering = true;
}
}
@Override
public void characters(char ch[], int start, int length) {
if(questionBuffering) {
sb.append(ch, start, length);
}
}
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
if (localName.equals("question")) {
questionBuffering = false;
questionList.add(sb.toString());
}
}
public ArrayList<String> getResult() {
return questionList;
};
}
}
這篇關(guān)于如何在java中將xml標(biāo)簽存儲(chǔ)為數(shù)組的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!