如何使用 StAX 向 XML 节点添加属性?
我需要在 XML 文件中生成具有以下结构的节点:
<node attribute0="value0" attribute1="value1" > </node>
如何在 StAX 中执行此操作?
编辑1: 我正在尝试 Lars Vogel 教程中的“3.4. 编写 XML 文件示例”部分的代码 (http://www.vogella.de/articles/JavaXML/article.html)
I need to generate a node in a XML file with the following structure:
<node attribute0="value0" attribute1="value1" > </node>
How can I do it in StAX?
Edit 1:
I'm trying the code from Section "3.4. Write XML File- Example" from Lars Vogel's tutorial (http://www.vogella.de/articles/JavaXML/article.html)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于您添加的链接,您似乎使用了以下语法。 此处查看他编写 RSS feed 的高级教程
given the link you added it appears you use teh below syntax. have a look at his advanced tutorial for writting RSS feed here
如果您想使用 XMLStreamWriter 而不是 XMLEventWriter,您可以按照以下方式进行操作:
而且对于 XMLEventWriter,有一个方法来创建属性:
问候,
最大限度
If you would use XMLStreamWriter instead of the XMLEventWriter, you can do it the following way:
But also for XMLEventWriter, there is a Method to create Attributes:
Regards,
Max