创建和使用Java语言编写XML文件为Android [英] creating and writing to an xml file in java for android

查看:124
本文介绍了创建和使用Java语言编写XML文件为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个很好的科学计算器,现在想输入和结果保存到一个文件中使用的PC上,并作为archieval报告,并需要一些帮助,整个过程。

我第一次创建所需的输出头和这样的在Excel中,然后保存为一个.xml文件,我想,这确实缓解了.xml文件的设置,因此所有的格式和列报头建立和所有我需要做的就是将这个文件或它在我的Java code cotents,我希望。

这是一个很好的方法这么远?

我想现在把我的数据到这个xml文件/布局特异性列,所以当我把这个.xml文件回到Excel将打开一个好看的报表中的PC上。没有公式不仅仅是数据。

我在正确的轨道上吗?任何好的链接起来啦?我关闭搜索如何,但也许有人可以让我开始的希望是这可以是oneonline一个很好的例子。

到目前为止,我已经做到了这一点:
 1.创建PC上的Excel文件,你需要格式化
 2.Save该文件为XML,Excel将插入标签用于格式化

现在我需要做的:
 3.Write的java code产生于Android类似的XML文件
 4.On的Andr​​oid,节省SD卡这个XML文件
 5.Transfer XML到PC,并打开Excel中

更新 - 所以它看起来像java.io.File的可能是我的解决办法,但一如既往没有简单容易。我的code可能是这样的,但我看到,我要和进入XML code作为字符串,因为他们有自己的报价和其他字符用java code冲突..这是问题我试图

  astring1 =< XML版本=1.0>?
                astring2 =<?MSO的应用程序id =Excel.Sheet取代;
                astring3 =工作簿的xmlns =瓮:架构 - 微软-COM:办公室:■preadsheet
                astring4 =的xmlns:O =瓮:架构 - 微软-COM:办公室:办公室                如果(((m1_ss_spinner.getSelectedItem()。的toString()。等于(方))))
                {
                    尝试
                    {
                        BufferedWriter将出=新的BufferedWriter(新FileWriter的(outfilename));
                        out.write astring1;
                        out.write astring2;
                        out.write astring3;
                        out.write astring4;
                        out.close();
                    }赶上(IOException异常五){
                    } //结束试                } //万一


解决方案

java.io.File中做了什么,我需要。正如我以前说过,我第一次ccreated从Excel XML文件,并使用out.write命令重新创建我的手机上的文件,从我的应用程序替换刚刚的answere。我需要包括回车和换行符这样的Excel会明白,一切运作良好。我excel.xml为515行,以便它占用了一些空间,在我的应用程序,但它精美的作品。我的计算器产生一些有趣的信息,并创建一个很好的报告,我发送到PC并Excel中打开它。这是一个重大的改进,以什么可编程计算器可以执行。而它在我的口袋里!

I have created a nice scientific calculator and now want to save inputs and results to a file for use on a PC and as an archieval report and need some help with the overall process.

I have first created the required output headers and such in excel and then saved it as an .xml file I am thinking that this really eased the setup of the .xml file so all the formatting and columns and headers are established and all I need to do is place this file or its cotents in my java code, I hope.

Is this a good approach so far?

I would like to now put my data into this xml file/layout is specif columns so when I put this .xml file back on a PC that excel will open a nice looking report. no formulas just the data.

Am I on the right track? any good links to get going? I am off to search for how to but maybe somebody can get me started The hopes are this can be a good example for oneonline.

So far I have done this: 1.Create an Excel file on PC with formatting that you need 2.Save that file as XML, Excel will insert Tags for formatting

now I need to do: 3.Write java code to generate similar XML file on Android 4.On Android, save this XML file on SD Card 5.Transfer the XML to PC and open that in Excel

Update - so it looks like java.io.file might be my solution but as always nothing simple is easy. My code might look like this but I see I am going to have problems with entering the xml code as strings because they have quotes of their own and other characters that conflict with java code.. this is what I am trying

                    astring1 = "<?xml version="1.0"?>";
                astring2 = <?mso-application progid="Excel.Sheet"?>;
                astring3 = Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet";
                astring4 =  xmlns:o="urn:schemas-microsoft-com:office:office"

                if (((m1_ss_spinner.getSelectedItem().toString().equals("Square"))))
                {
                    try 
                    {
                        BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
                        out.write astring1;
                        out.write astring2;
                        out.write astring3;
                        out.write astring4;
                        out.close();
                    } catch (IOException e) {
                    } //end try

                } //end if

解决方案

java.io.file did exactly what I needed. As I said before, I first ccreated the xml file from excel and used the out.write command to recreate the file on my phone, substituting just the answere from my app. I needed to include carriage return and line feeds so excel would understand and everything works well. My excel.xml was 515 lines so it takes up some room in my app but it works beautifully. My calculator creates some interesting information and creates a nice report which I send to a pc and have excel open it. This is a major improvement to what a programable calculator can perform. And its in my pocket!

这篇关于创建和使用Java语言编写XML文件为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆