1

我有 xml 文件,我想添加元素并用 joox 保存

我的xml文件

    <document>
  <library name="Amazon">
    <books>
      <book id="1">
        <name>1984</name>
        <authors>
          <author>George Orwell</author>
        </authors>
      </book>
      <book id="2">
        <name>Animal Farm</name>
        <authors>
          <author>George Orwell</author>
        </authors>
      </book>
    </books>
  </library>
</document>

我的java代码

        File xmlfile = new File("C:\\SiteMap\\Doc.xml");

        Document document = $(xmlfile).document();

Match x = $(document).xpath("//book[@id = 1]");
        System.out.println(""+x.toString());

       //this my modification 
        x.append("<loc/>");       

但现在我想保存这个修改我的 Doc.xml 文件

4

1 回答 1

0

只需用于$(document).write(xmlfile);覆盖文件。

于 2016-07-19T15:46:08.577 回答