Back to project page TheFirstMyth02.
The source code is released under:
MIT License
If you think the Android project TheFirstMyth02 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.game.commen; /*from w ww .ja v a 2 s .c om*/ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import com.game.base.PubSet; import com.game.data.StroyTipData; public class GameXmlcommen { String Stroy = "Stroy"; String NAME = "name"; String StroyInfo = "StroyInfo"; String HeadUrl = "HeadUrl"; String Todo = "Todo"; String chapter = "chapter"; String progress = "progress"; // ????????????? /** * ????fileName??xml???? */ public List<StroyTipData> getRiversFromXml(String fileName) { List<StroyTipData> rivers = new ArrayList<StroyTipData>(); DocumentBuilderFactory factory = null; DocumentBuilder builder = null; Document document = null; InputStream inputStream = null; // ????xml?? factory = DocumentBuilderFactory.newInstance(); try { // ??xml?????? builder = factory.newDocumentBuilder(); inputStream = PubSet.context.getResources().getAssets() .open(fileName); document = builder.parse(inputStream); // ???Element Element root = document.getDocumentElement(); NodeList nodes = root.getElementsByTagName(Stroy); // ?????????????,rivers ???river StroyTipData stroydata = null; for (int i = 0; i < nodes.getLength(); i++) { stroydata = new StroyTipData(); // ????Stroys???? Element riverElement = (Element) (nodes.item(i)); // ????Stroys?name??? stroydata.setStroyName(riverElement.getAttribute(NAME)); stroydata.setChapter(Integer.parseInt(riverElement .getAttribute(chapter))); stroydata.setProgress(Integer.parseInt(riverElement .getAttribute(progress))); // ????river?introduction?? Element introduction = (Element) riverElement .getElementsByTagName(StroyInfo).item(0); stroydata.setStroyInfo(introduction.getFirstChild() .getNodeValue()); Element el_headurl = (Element) riverElement.getElementsByTagName( HeadUrl).item(0); stroydata.setHeadUrl(el_headurl.getFirstChild().getNodeValue()); Element el_Todo = (Element) riverElement.getElementsByTagName( Todo).item(0); stroydata.setTodoInfo(el_Todo.getFirstChild().getNodeValue()); rivers.add(stroydata); } } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return rivers; } }