Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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文件保存在同一个资源文件夹中_Android_Xml_File - Fatal编程技术网

如何在android中修改意味着将xml文件保存在同一个资源文件夹中

如何在android中修改意味着将xml文件保存在同一个资源文件夹中,android,xml,file,Android,Xml,File,我正在资源文件夹中实现读取和写入xml读取是可以的,如何修改此xml文件并另存为相同的资源文件夹 我正在使用这段代码阅读它的工作原理,如何修改xml文件 EditText myXmlContent = (EditText)findViewById(R.id.my_xml); String stringXmlContent; try { stringXmlContent = getEventsFromAnXML(this);

我正在资源文件夹中实现读取和写入xml读取是可以的,如何修改此xml文件并另存为相同的资源文件夹

我正在使用这段代码阅读它的工作原理,如何修改xml文件

EditText myXmlContent = (EditText)findViewById(R.id.my_xml);
        String stringXmlContent;
        try {
            stringXmlContent = getEventsFromAnXML(this);
            myXmlContent.setText(stringXmlContent);
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private String getEventsFromAnXML(Activity activity) throws XmlPullParserException, IOException
    {
        StringBuffer stringBuffer = new StringBuffer();
        Resources res = activity.getResources();
        XmlResourceParser xpp = res.getXml(R.xml.nab);
        xpp.next();
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT)
        {
            if(eventType == XmlPullParser.START_DOCUMENT)
            {
                stringBuffer.append("--- Start XML ---");
            }
            else if(eventType == XmlPullParser.START_TAG)
            {
                stringBuffer.append("\nSTART_TAG: "+xpp.getName());
            }
            else if(eventType == XmlPullParser.END_TAG)
            {
                stringBuffer.append("\nEND_TAG: "+xpp.getName());
            }
            else if(eventType == XmlPullParser.TEXT)
            {
                stringBuffer.append("\nTEXT: "+xpp.getText());
            }
            eventType = xpp.next();
        }
        stringBuffer.append("\n--- End XML ---");
        return stringBuffer.toString();
    }
}
显示阅读目的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<EditText android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/my_xml"
    />
    <Button android:text="Write" 
          android:id="@+id/button1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content">
    </Button>

</LinearLayout>


如何修改xml文件另存为资源文件夹或SD卡位置转发一些建议提前感谢

res/资源是只读的。您可以将其保存为内部文件或sd卡。

没问题,我保存在sdcrad中如何在android中编写(修改)此xml文件请提出一些建议