简体   繁体   English

写入XML文件

[英]Write to XML-File

I have a special Problem. 我有一个特殊的问题。

I'm loading a XML File from Web with different tags like <job_id> . 我正在从Web加载带有<job_id>类的不同标签的XML文件。 These XML Data is written to a file named xmlInformations.xml . 这些XML数据被写入名为xmlInformations.xml的文件中。 Every Information is loaded from file to a ArrayList<Hashmap<String,String>> named taskItems 每个信息都从文件加载到名为taskItemsArrayList<Hashmap<String,String>>

public void setListTaskData(String filename) {

    XMLParser parser = new XMLParser();
    Document doc = parser.getDomElement(readFromFile(filename));

    NodeList nodeListTasks = doc.getElementsByTagName(KEY_TASK);

    for (int i = 0; i < nodeListTasks.getLength(); i++) {
        HashMap<String, String> map = new HashMap<>();
        Element e = (Element) nodeListTasks.item(i);

        map.put(KEY_TASK_UUID_OBJ, parser.getValue(e, KEY_TASK_UUID_OBJ));
        map.put(KEY_TASK_TITLE, parser.getValue(e, KEY_TASK_TITLE));
        map.put(KEY_TASK_INFO, parser.getValue(e, KEY_TASK_INFO));
        map.put(KEY_TASK_OBJECT, parser.getValue(e, KEY_TASK_OBJECT));
        map.put(KEY_TASK_LOCATION, parser.getValue(e, KEY_TASK_LOCATION));
        map.put(KEY_TASK_OBJECT_ID, parser.getValue(e, KEY_TASK_OBJECT_ID));
        map.put(KEY_TASK_OBJECT_SNR, parser.getValue(e, KEY_TASK_OBJECT_SNR));
        map.put(KEY_TASK_REGISTRATION_ID, parser.getValue(e, KEY_TASK_REGISTRATION_ID));
        map.put(KEY_TASK_TASKIMAGE, parser.getValue(e, KEY_TASK_TASKIMAGE));
        map.put(KEY_TASKIMAGE, parser.getValue(e, KEY_TASKIMAGE));
        map.put(KEY_TASK_HEADLINE, parser.getValue(e, KEY_TASK_HEADLINE));
        map.put(KEY_TASK_SUBJECT, parser.getValue(e, KEY_TASK_SUBJECT));
        map.put(KEY_TASK_ACTION, parser.getValue(e, KEY_TASK_ACTION));
        map.put(KEY_TASK_PRIORITY_COLOR, parser.getValue(e, KEY_TASK_PRIORITY_COLOR));
        map.put(KEY_TASK_STATUS, parser.getValue(e, KEY_TASK_STATUS));
        taskItems.add(map);
    }
}

They will displayed on a ListView . 它们将显示在ListView After i clicked on an Item, it starts a new Activity named SingleTaskActivity . 单击项目后,它将启动一个名为SingleTaskActivity的新Activity This Activity gets the Informations by an IntentExtra from TaskListActivity . Activity通过TaskListActivityIntentExtra获取信息。

It looks like: 看起来像:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    //neue Oberflaeche starten
    Intent in = new Intent(this, SingleTaskList.class);;
    in.putExtra("taskItems", taskItems.get(position));

    startActivity(in);
}

The SingleTaskActivity displays now the Informations. SingleTaskActivity现在显示信息。

    super.onCreate(savedInstanceState);

    Intent i = getIntent();
    ListView lv = getListView();
    lv.setOnItemClickListener(this);
    Serializable xmlFileNames = i.getSerializableExtra("xmlFileNames");
    String filename = xmlFileNames.toString()+".kx_task";
    setListTaskData(filename);

    CustomAdapterTasks adapterTasks = new CustomAdapterTasks(this,taskItems);
    setListAdapter(adapterTasks);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

The User now can type something in an Edittext or take a Picture. 用户现在可以在Edittext键入Edittext或拍照。

And here is the Problem: 这是问题所在:

When a User finishes his work and is clicking on the button "save" at the bottom, how can i save all these Informations into the File at the same position in that XML File? 当用户完成工作并单击底部的“保存”按钮时,如何将所有这些信息保存到该XML文件中相同位置的文件中?

I hope it's clear what my Problem is. 我希望我的问题很清楚。 I'm working now about 12 Days but didn't found out how it works. 我现在大约工作12天,但没有发现它是如何工作的。

Thank you! 谢谢!

King Regards 国王的问候

Use startactivityforresult() and @ override onactivityresult for the first Activity to save and restore position line in XML file. 使用startactivityforresult()和@ override onactivityresult作为第一个Activity,以保存和恢复XML文件中的位置行。 For instance, read this topic: https://stackoverflow.com/a/10407371/1979882 例如,请阅读以下主题: https : //stackoverflow.com/a/10407371/1979882

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM