简体   繁体   English

我有一个包含数据的字符串,我想将此字符串文件存储到 xml 中。 我应该怎么办?

[英]I have a string with data i want to store this string file into xml. what should i do?

i have a string which contain..我有一个字符串,其中包含..

<response type="1">
<terminal_id>1000099999</terminal_id>
<merchant_id>10004444</merchant_id>
<merchant_info>Mc Donald's - Abdoun</merchant_info>
<transaction_id>7777771</transaction_id>
<process_status>1</process_status>
<process_status_desc>Success</process_status_desc>
<process_date>30/06/2011 12:39:32</process_date>
<menu_version_id>1</menu_version_id>
<menu>
<menu type="campaigns">
<menu campaign_id="1" title_en="2nd sandwich free" title_ar="??????? ????? ??????">
<menu>
</menu>
<specific_inputs>
<input_item key="amount" type="float" title_en="Amount" title_ar="??????"/>
</specific_inputs>
</menu>
</menu>
<menu type="fixed_text" id="1" title_en="Help" title_ar="??????">
<text_en>When making sales, first the campaign should be selected. Then the </text_en>
<text_ar>When making sales, first the
</text_ar>
</menu>
<menu type="fixed_text" id="2" title_en="Support" title_ar="???">
<text_en>Mobilera: 06-583 3500 or 06-583 3400</text_en>

<text_ar>Mobilera: 06-583 3500 or 06-583 3400</text_ar>
</menu>
</menu>
</response>

<response type="1">
<terminal_id>1000099999</terminal_id>
<merchant_id>10004444</merchant_id>
<merchant_info>Mc Donald's - Abdoun</merchant_info>
<transaction_id>7777771</transaction_id>
<process_status>1</process_status>
<process_status_desc>Success</process_status_desc>
<process_date>30/06/2011 12:39:32</process_date>
<menu_version_id>1</menu_version_id>
<menu>

<menu type="campaigns">
<menu campaign_id="1" title_en="2nd sandwich free" title_ar="??????? ????? ??????">
<menu>
</menu>
<specific_inputs>
<input_item key="amount" type="float" title_en="Amount" title_ar="??????"/>
</specific_inputs>
</menu>
</menu>
<menu type="fixed_text" id="1" title_en="Help" title_ar="??????">
<text_en>When making sales, first the campaign should be selected. Then the </text_en>
<text_ar>When making sales, first the
</text_ar>
</menu>
<menu type="fixed_text" id="2" title_en="Support" title_ar="???">
<text_en>Mobilera: 06-583 3500 or 06-583 3400</text_en>

<text_ar>Mobilera: 06-583 3500 or 06-583 3400</text_ar>
</menu>
</menu>
</response>

how can this string data store into xml.这个字符串数据如何存储到 xml 中。

Use the following code to create xml file from your string使用以下代码从您的字符串创建 xml 文件

String str = //your xml file
byte[] stringInByte = str.getBytes();

File myxmlFile = new File(path of file+"mydata.xml"); //mydata.xml is the name of file //that you want to create

            // write the bytes in file
            FileOutputStream fo = new FileOutputStream(myxmlFile);
            fo.write(stringInByte);
            fo.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

I had tryed:我试过:

String xmlRecords = "<data>string</data>";

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document d1 = builder.parse(new InputSource(new StringReader(xmlRecords)));

it will help me a lot.这对我有很大帮助。

I think this is a Java question.我认为这是一个 Java 问题。 If I understood you corretly you just have to save the String into a file as http://www.roseindia.net/java/beginners/java-write-to-file.shtml如果我正确理解您,您只需将字符串保存为http://www.roseindia.net/java/beginners/java-write-to-file.shtml

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

相关问题 如果我只想将文本字符串(安全数据)从android手机发送到android wear(手表),该怎么办? - If I want to send just text string(secure data) from android phone to android wear(watch), what should I do for that? 如何将字符串存储到android中的文件 - How do I Store a String to a file in android 如何从xml更改ActionBar的颜色。 - How do I change the color of my ActionBar from the xml.? 如何将XML字符串从文件读取为字符串? - How do I read XML string from file into a String? .apk文件应该怎么办? - What I should do to have my .apk file? 在xml中为按钮定义了自定义形状。 现在,我想动态更改颜色。 怎么样? - Defined custom shape for button in xml. Now I want to change the color dynamically. How? Android XML。 ID字符串中星号的作用是什么? - Android XML. What is the purpose of the star in the ID string? 我如何在不使用 String.xml 的情况下更改印地语和英语的整个应用程序文本,因为我有很多数据 - How Do i change my whole app text in hindi and english without using String.xml because i have to much data 如果我想在 Android Debounce 中添加条件,我该怎么做? - What should I do if I want to add a condition to Android Debounce? 当字符串像数值一样命名时我该怎么办 - what i have to do when string named like a numerical value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM