【发布时间】:2015-09-03 14:17:45
【问题描述】:
我目前正在尝试使用带有 Java 语言的 DOM 获取 xml 的一部分。 例如,我希望能够将 XML 元素(标签)的原始代码及其子节点作为字符串作为字符串。
例子:
XML 文件:
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
我们的目标是为第一本书元素添加这个:
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
我正在查看 Element 方法,但在其中找不到对此有用的方法。
谢谢。
【问题讨论】: