story.x<?xml version="1.0" encoding="UTF-8"?>
- <story>
- <talks id="t000" >
- <talk name="跳绳小孩">一根绳,两人摇。摇下来,像小船。摇上去,像小桥。你来跳,我来跳,蹦蹦跳跳多可爱。</talk>
- <talk name="跳绳小孩">姐姐,你要不要一起来玩呀!</talk>
- <talk name="赵灵儿">不了,姐姐在找蜀山的入口,不知你们是否知道?</talk>
- <talk name="跳绳小孩" >擂台上的哥哥好像自称是蜀山弟子,也许他会知道。</talk>
- </talks>
- <talks id="t001" >
- <talk name="旺财">汪汪,汪汪……</talk>
- </talks>
- <talks id="t002" >
- <talk name="算命先生">小姐,我观你颧骨平滑,下巴圆润饱满,正是旺夫之相呀。 等等,眉宇间桃花隐现……哈哈,今日就是你们的相遇之时。</talk>
- <talk name="算命先生">不如把你的生辰八字告诉我,我帮你好好的算算姻缘。</talk>
- <talk name="赵灵儿">不了,我要抓紧时间上蜀山。</talk>
- <talk name="算命先生" >蜀山?锁妖塔倒塌,现在蜀山一片大乱,我劝你还是最好不要上蜀山。</talk>
- </talks>
- <talks id="t003" >
- <talk name="李逍遥">姑娘,您好,在下李逍遥,是名蜀山弟子。</talk>
- <talk name="李逍遥">听闻村外有些妖怪出没,残害了不少村民,我正欲去制服他们。不知姑娘是否愿意同行?</talk>
- <talk name="赵灵儿">我叫赵灵儿,正想上蜀山,这样吧,我帮你捉妖,你带我上蜀山,如何?</talk>
- <talk name="李逍遥" >好的,那我们一会村外见。</talk>
- </talks>
- <talks id="t004" >
- <talk name="地痞">叫你不好好学Android。</talk>
- <talk name="地痞">叫你不认真敲代码!</talk>
- <talk name="落难书生">女侠救我呀!</talk>
- <talk name="赵灵儿">不读书,谁也救不了你。</talk>
- </talks>
- </story>ml
- public ArrayList<Talk> getTalksForXML(String fileName, String id) {
- ArrayList<Talk> aTalks = new ArrayList<Talk>();
- DocumentBuilderFactory aDocumentBuilderFactory = DocumentBuilderFactory
- .newInstance();
- try {
- DocumentBuilder aDocumentBuilder = aDocumentBuilderFactory
- .newDocumentBuilder();
- Document aDocument = aDocumentBuilder.parse(getAssets().open(
- fileName));
- Element rootElement = aDocument.getDocumentElement();
- NodeList aNodeLists = rootElement.getElementsByTagName("talks");
- for (int i = 0; i < aNodeLists.getLength(); i++) {
- Element aTalksElement = (Element) aNodeLists.item(i);
- if (id.equals(aTalksElement.getAttribute("id"))) {
- NodeList aNodeList2 = aTalksElement
- .getElementsByTagName("talk");
- for (int j = 0; j < aNodeList2.getLength(); j++) {
- Element aTalkElement = (Element) aNodeList2.item(j);
- Talk aTalk = new Talk(aTalkElement.getTextContent(),
- aTalkElement.getAttribute("name"));
- aTalks.add(aTalk);
- }
- }
- }
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return aTalks;
- }