假设我有一个这样的 XML 文件(bookstore.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>
我想删除= JK罗琳的book
元素。
我知道我可以像这样(Jython)获得所有匹配作者的元素author
docFactory = DocumentBuilderFactory.newInstance()
docBuilder = docFactory.newDocumentBuilder()
doc = docBuilder.parse(bookstore.xml)
list = doc.getElementsByTagName("author")
我想将修改后的 XML 树写入 bookstore.xml。
谢谢 !