Android 我有一个字符串,其中包含要将该字符串文件存储到xml中的数据。我该怎么办?
我有一个字符串,其中包含Android 我有一个字符串,其中包含要将该字符串文件存储到xml中的数据。我该怎么办?,android,xml,Android,Xml,我有一个字符串,其中包含 <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&
<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中。我认为这是一个Java问题。如果我正确地理解了您的意思,您只需将字符串保存到文件中,作为我认为这是一个Java问题。如果我正确理解了您的意思,您只需将字符串保存到文件中,即使用以下代码从字符串创建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();
}
使用以下代码从字符串创建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();
}
我试过:
String xmlRecords = "<data>string</data>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document d1 = builder.parse(new InputSource(new StringReader(xmlRecords)));
这对我会有很大帮助。我试过:
String xmlRecords = "<data>string</data>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document d1 = builder.parse(new InputSource(new StringReader(xmlRecords)));
这对我会有很大帮助。这不是已经是XML了吗?我想也许这个问题需要澄清。@DrG我有一个类似xml的字符串,我想把它存储为xml,我该怎么做?但我只想取元素名。我应该把这个字符串设为new.xml吗?这不是已经是xml了吗?我想也许这个问题需要澄清。@DrG我有一个类似xml的字符串,我想把它存储为xml,我该怎么做?但我只想取元素名。我应该把这个字符串设为new.xml吗?我想把上面的[containt]存储在xxx.xml文件中。对不起,你能再解释一下吗?兄弟,我觉得整个字符串都是字符串。我想把这个字符串存储为xml文件。我想把上面的]containt存储在xxx.xml文件中。对不起,你能再解释一下吗?兄弟,我觉得这个字符串是完整的。我想将此字符串存储为xml文件。我想在我的资产中存储什么是我的路径。我想在我的资产中存储什么是我的路径。