从Java创建XML文件 [英] Creating XML files from Java

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

问题描述

您好!

我正在尝试从Java中创建XML文件。在做了一些研究后,我很困惑 - 标准库中似乎有很多很多类(加上更多的外部),它们以某种方式处理XML,但我不知道,哪些会适合我。这就是我想要做的事情:


我想阅读TXT文件(没问题),提取正确的信息(到目前为止仍然没问题)然后创建一个XML文件,包含我刚从TXT文件中提取的数据。我已经为我的XML文件设计了一个结构,现在我需要计算机为我创建它们。


那么,你会推荐哪些课程,你能不能给我一个例子说明如何使用它们或指导我一个好例子的教程?


问候,

Nepomuk

Hi there!
I''m trying to create a XML file from within Java. After doing a bit of research, I''m quite confused - there seem to be many, many classes in the standard libraries (plus many more outside), that somehow deal with XML, but I don''t know, which ones would be right for me. Here''s what I want to do:

I want to read TXT files (no problem with that), extract the right information (still no problem so far) and then create an XML file, that holds the data I just extracted from the TXT files. I have designed a structure for my XML files, now I need the computer to create them for me.

So, which classes would you recommend and can you either give me an example of how to use them or direct me to a tutorial with a good example?

Greetings,
Nepomuk

推荐答案

我建​​议你从 JAXP 开始



我建议你先从 JAXP



感谢您的链接,但我不确定,这就是我在寻找的东西对于。原因如下:

Thanks for the link, but I''m not sure, it''s what I''m looking for. Here''s why:


用于XML处理的Java API [...]是Java XML编程API之一。它提供了验证和解析 XML文档的功能。
The Java API for XML Processing [...] is one of the Java XML programming APIs. It provides the capability of validating and parsing XML documents.



我没有尝试验证或解析任何XML文档(目前),我正在尝试创建它们。我还查看了 saxproject.org ,看来,他们只是阅读文件而不是创建它们在他们的例子中。另外,我用Eclipse浏览了 org.xml.sax 库,找不到任何关于写作的内容。


我刚刚检查过错误的地方还是我需要别的东西?如果是这样,什么?


谢谢,

Nepomuk


*编辑*我刚发现界面 XMLStreamWriter - 可能是是正确的路径?或者也许是 XMLEncoder ? (虽然我不打算使用JavaBeans,但它可能是一个好主意 - 我必须考虑它。)


*编辑2 *好吧,它可能不是XMLStreamWriter,因为我需要一些东西,这在JRE 1.4.x中是可用的,而且似乎并不存在。仍然检查XMLEncoder。

I''m not trying to validate or parse any XML documents (at the moment), I''m trying to create them. I also checked at saxproject.org and it seems, they only read files instead of creating them in their examples. Also, I had a look through the org.xml.sax library with Eclipse and couldn''t find anything about writing.

Have I just checked the wrong places or do I need something else? If so, what?

Thanks,
Nepomuk

*EDIT* I just found the interface XMLStreamWriter - might that be the right path to be looking at? Or maybe the XMLEncoder? (Although I wasn''t planning to use JavaBeans, but it might be a good idea - I''ll have to think about it.)

*EDIT 2* OK, it probably isn''t the XMLStreamWriter, as I need something, that''s available in JRE 1.4.x, and that doesn''t seem to. Still checking out the XMLEncoder.


好的,我想我可能只是使用FileWriter。如果有人有更好的建议,请提出来!


问候,

Nepomuk
OK, I guess I''ll probably just use a FileWriter. If anyone has a better suggestion, please come forward with it!

Greetings,
Nepomuk


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

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