我有一个带数据的字符串,我想把这个字符串文件存储到xml中。我应该做什么?

时间:2021-12-13 16:27:19

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中。

3 个解决方案

#1


2  

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();
        }

#2


2  

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.

这对我有很大帮助。

#3


1  

I think this is a Java question. 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

我认为这是一个Java问题。如果我很理解您的意思,您只需将字符串保存为http://www.roseindia.net/java/beginners/java-write-to-file.shtml文件

#1


2  

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();
        }

#2


2  

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.

这对我有很大帮助。

#3


1  

I think this is a Java question. 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

我认为这是一个Java问题。如果我很理解您的意思,您只需将字符串保存为http://www.roseindia.net/java/beginners/java-write-to-file.shtml文件