-1

assetsフォルダに置いたxmlデータベースからデータを抜き出したいです。// データベースのサンプル

<?xml version="1.0" encoding="utf-8" ?>
   <Levels>

   <level id ="0">
     <start>3,2</start>
   <one>1,1</one>
    </level>
    <level id ="1">
<start>3,2</start>
  <one>4,1</one>
     </level>
  </Levels>

データ プルが id で行われるようにしたいです。たとえば、id=0 は < start>3,2< /start> < one>1,1< /one> を返します。問題が 1 つあります。方法がわかりません。助けてください //--------------------------------- -------------------------------------------------- ---- EDIT : エラーが発生しました。xmlparser クラスを確認してください。

 package com.example.com.worfield.barak;
   import java.io.IOException;
 import java.io.StringReader;

     import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

 import org.apache.http.impl.client.DefaultHttpClient;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;

 import android.content.Context;
 import android.sax.Element;
  import android.util.Log;


public class XMLParser 
 {
Context context;

   public XMLParser(Context c)
     {

   context = c;
 }

public Document getDomElement()
{
    Document doc = null;
    try
    {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    doc = db.parse( context.getAssets().open("Level5X5Three.xml"));

    }
    catch(Exception ex)
    {

        Log.e("xml parse error", "eror in getdomelement()");
    }
        return doc;
}
public String getValue(Element e, String str) 
{      
    NodeList n = ((Document) e).getElementsByTagName(str);        //problem
    return this.getElementValue(n.item(0));
}

public final String getElementValue( Node elem ) 
{
         Node child;
         if( elem != null){
             if (elem.hasChildNodes()){
                 for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                     if( child.getNodeType() == Node.TEXT_NODE  ){
                         return child.getNodeValue();
                     }
                 }
             }
         }
         return "";
  } 
    }
4

1 に答える 1