Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中本地xml文件的Sax解析_Android_Sax - Fatal编程技术网

android中本地xml文件的Sax解析

android中本地xml文件的Sax解析,android,sax,Android,Sax,我想分析它存在于xml文件夹中的国家 在文件位置中,我遇到错误 任何帮助请使用正确的原始文件路径 您可以将XML文件放在原始文件夹或资产文件夹中 对于原始文件夹,您可以按以下方式获取文件: int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.xml"); File f = new File(context.getResources().openRawResource(resou

我想分析它存在于xml文件夹中的国家

在文件位置中,我遇到错误
任何帮助请使用正确的原始文件路径

您可以将XML文件放在原始文件夹或资产文件夹中

对于原始文件夹,您可以按以下方式获取文件:

int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.xml");
File f = new File(context.getResources().openRawResource(resourceId));

从阿塞特

AssetManager assetManager = getAssets();
inputStream = assetManager.open("readme.xml")
来自SD卡

FileInputStream in = new FileInputStream("/sdcard/text.txt");
//对于资产以及资源ans以及SD卡存储文件,请使用完整链接

试试看
{  
//从/res/raw文件夹读取myxml.xml文件
InputStream is=getResources().openRawResource(R.raw.country);
Log.i(“标记”,“is值==>”+is);
DocumentBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc=builder.parse(为空);
//获取根节点
NodeList NodeList=doc.getElementsByTagName(“斯卡达特地区国家”);
Log.i(“标记”,“节点列表长度--”+nodeList.getLength());//输出:--1
Log.i(“标记”,“节点列表名称--”+nodeList.item(0).getNodeName());//输出:-消息

对于(int j=0;jPost)错误消息,可能是来自logcat的异常堆栈跟踪错误是什么?显示logcat输出。能否发布错误消息,以便人们能够给出准确答案。很抱歉,它不起作用。还有其他解决方案吗
 InputStream in = this.getResources().openRawResource(R.raw.myxml); 
AssetManager assetManager = getAssets();
inputStream = assetManager.open("readme.xml")
FileInputStream in = new FileInputStream("/sdcard/text.txt");
try  
{  
    //Read myxml.xml file from /res/raw folder  
    InputStream is=getResources().openRawResource(R.raw.country);  

    Log.i("TAG","is value==>"+is);  
    DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder();  
    Document doc=builder.parse(is, null);  

    //get the root node   
    NodeList nodeList=doc.getElementsByTagName("skadate_location_country");  

    Log.i("TAG","nodeList Length --" + nodeList.getLength()); //output:- -1  
    Log.i("TAG","nodeList name --" + nodeList.item(0).getNodeName()); //output:- message  
    for(int j=0; j<nodeList.getLength(); j++) {
       Node nodee=nodeList.item(j); 
       for(int i=0;i<nodee.getChildNodes().getLength();i++)
       {  
           Node node=nodee.getChildNodes().item(i);  
           if(node.getNodeName().equalsIgnoreCase("Country_str_code")){  
               Log.i("TAG","from node::" + node.getTextContent()); 
               countryname.add(node.getTextContent());
               countrySelector.setAdapter(countryname);
               countrySelector.setOnItemSelectedListener(this); 
           }  
           else if(node.getNodeName().equalsIgnoreCase("Country_str_name")){  
               Log.i("TAG","to node::" + node.getTextContent());  
           }  
       }
    }
    is.close();  
} catch(Exception e) {  
   System.out.println("ERROR while parsing xml:----" + e.getMessage());  
}