1. //添加一条属性 Attribute a = new Attribute("hot","true"); book.addAttribute(a); book.setAttributes(books); 改成 Attribute a = new Attribute("hot", "true"); book.setAttribute(a); 2. //得到指定的字元素 Element price = book.getChild("price"); author.setText(Float.toString(50.0f)); 改成 Element price = book.getChild("price"); price.setText(Float.toString(50.0f));这样可以运行了。
Attribute a = new Attribute("hot","true"); book.addAttribute(a); Element author = book.getChild("author"); //得到指定的字元素 System.out.println("author: "+author.getText()); author.setText("王五"); //将作者改为王五
Element price = book.getChild("price"); //得到指定的字元素 price.setText(Float.toString(50.0f));我做过了,应该没有问题的.
高版本的JDom把AddAttributes改成了setAttributes
//添加一条属性
Attribute a = new Attribute("hot","true");
book.addAttribute(a);
book.setAttributes(books);
改成
Attribute a = new Attribute("hot", "true");
book.setAttribute(a);
2.
//得到指定的字元素
Element price = book.getChild("price");
author.setText(Float.toString(50.0f));
改成
Element price = book.getChild("price");
price.setText(Float.toString(50.0f));这样可以运行了。
book.addAttribute(a); Element author = book.getChild("author"); //得到指定的字元素
System.out.println("author: "+author.getText());
author.setText("王五"); //将作者改为王五
Element price = book.getChild("price"); //得到指定的字元素
price.setText(Float.toString(50.0f));我做过了,应该没有问题的.