<param name="name1" value="value1"/>
<param name="name2" value="value2"/>
<param name="name3" value="value3"/>
<param name="name4" value="value4"/>
<param name="name5" value="value5"/>
我有一个XML格式是这样的,
怎么实现根据name修改value的值?
我试了下用Node,取不到name和value的值.......
XML 解析 修改 Java
------解决方案--------------------
代码需要导入dom4j.jar
public static void main(String[] args)
{
//修改条件和修改的值
final String nameStr = "name2";
final String valueStr = "value222";
File xmlFile = new File("D:\\java\\test_java\\someXML.xml");
SAXReader reader = new SAXReader();
XMLWriter output = null;
InputStream isr = null;
try
{
//定义文件输入流
isr = new FileInputStream(xmlFile);
//以UTF-8的编码方式读取配置文件
Document document = reader.read(new InputStreamReader(isr, "UTF-8"));
//Document document = reader.read(xmlFile);
Element root = document.getRootElement();