我很困惑如何编辑xml内容, 例如我有一个xml文件
<configuration>
<steps>
<step>
<step1>abc</step1>
<step2>def</step2>
</step>
<step>
<step1>pqr</step1>
<step2>xyz</step2>
</step>
</steps>
</configuration>
如何编辑“xyz”到“stu”
我尝试使用commons-configuration-1.6.jar的XMLConfiguration
setProp(String name, String tochange){ // here I pass name as "pqr" , toChange as "stu"
XMLConfiguration config = new XMLConfiguration("config.xml");
//TODO: config.setProperty("steps.step.step2",tochange); Here I am not sure what to do..
}
答案 0 :(得分:1)
答案 1 :(得分:0)
试试这个
XMLConfiguration config = new XMLConfiguration("config.xml");
config.addProperty("steps.step(2).step2",tochange);
答案 2 :(得分:0)
为了编辑&#34; xyz&#34;到&#34; stu&#34;并显示xml
公共类DataChange {
public static void main(String[] args) throws ConfigurationException {
XMLConfiguration config = new XMLConfiguration("change.xml");
config.setProperty("steps.step(1).step2", "stu");
StringWriter s = new StringWriter();
config.save(s);
System.out.println(s.toString());
}
}