У меня есть строка с данными, я хочу сохранить этот файл строки в XML. что я должен делать?

1

У меня есть строка, которая содержит..

<response type="1">
<terminal_id>1000099999</terminal_id>
<merchant_id>10004444</merchant_id>
<merchant_info>Mc Donald - 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 - 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.

  • 1
    Разве это уже не XML? Я думаю, что, возможно, этот вопрос требует уточнения.
  • 0
    @DrG У меня есть строка как XML, я хочу сохранить ее как XML, что мне делать?
Показать ещё 4 комментария
Теги:

3 ответа

2
Лучший ответ

Я попробовал:

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

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

это мне очень поможет.

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();
        }
  • 0
    String str = // ваш XML-файл ??? это должна быть моя строка на?
  • 0
    да это твоя строка
Показать ещё 2 комментария
1

Я думаю, что это вопрос Java. Если я правильно понял вас, вам просто нужно сохранить String в файл, как http://www.roseindia.net/java/beginners/java-write-to-file.shtml

  • 0
    Я хочу сохранить выше] содержат в файле xxx.xml.
  • 0
    Извините, вы можете объяснить это немного больше?
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню