Android Open Source - TheFirstMyth02 Game Xmlcommen






From Project

Back to project page TheFirstMyth02.

License

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.

Java Source Code

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;
  }
}




Java Source Code List

.Test.java
com.game.base.BaseInfo.java
com.game.base.GameBackGround.java
com.game.base.GameChapterBaseSet_Shentan.java
com.game.base.GameMap.java
com.game.base.PubSet.java
com.game.commen.AStarMap.java
com.game.commen.AStarNode.java
com.game.commen.AStar.java
com.game.commen.ActionToDo.java
com.game.commen.BitmapTouchChecker.java
com.game.commen.BitmapUtil.java
com.game.commen.Direction.java
com.game.commen.EffectName.java
com.game.commen.GameXmlcommen.java
com.game.commen.GetImgCommen.java
com.game.commen.IrregularButton.java
com.game.commen.MapName.java
com.game.commen.Paintforziti.java
com.game.commen.ToDo.java
com.game.data.BaseInfo.java
com.game.data.RoleData_Main.java
com.game.data.RoleData.java
com.game.data.StroyTipData.java
com.game.effect.SpecialEffect.java
com.game.fengshen.GameActivity.java
com.game.fengshen.GameMainActivity.java
com.game.fengshen.GameView.java
com.game.fengshen.MoveTest.java
com.game.renwu.Objs.java
com.game.renwu.SpiritMain.java
com.game.renwu.Spirit_Main.java
com.game.renwu.Spirit_NPC.java
com.game.renwu.Spirit.java
com.game.renwu.Spiritgirl.java
com.game.stroy.MainStroy.java
com.game.tip.PublicTips.java