我有一个包含..
的字符串<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>
如何将此字符串数据存储到xml中。
答案 0 :(得分:2)
使用以下代码从字符串
创建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();
}
答案 1 :(得分:2)
我曾尝试过:
String xmlRecords = "<data>string</data>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document d1 = builder.parse(new InputSource(new StringReader(xmlRecords)));
这对我很有用。
答案 2 :(得分:1)
我认为这是一个Java问题。如果我理解你,你只需将字符串保存到文件http://www.roseindia.net/java/beginners/java-write-to-file.shtml