繁体   English   中英

如何替换XML文件中的内容值?

[英]How to replace content values in XML files?

什么是最好或最容易使用的库来执行XML替换?

例:

<content>
<employee>
  <name>membersound</name>
  <id>1</id>
</employee>
</content>

我想寻找标签

<employee><name>

并替换<id>标记中的内容。

您可以定义一个xslt,它会查找<employee>元素并替换/删除其中的<id>

正如您在其他问题中一样,您可以尝试Jsoup-即使它是Html Parser。

Element xmlDoc = // ...


/* If 'name' is not relevant you can use "employee > id" instead */
for( Element e : xmlDoc.select("employee > name + id") )
{
    e.text("30");
}

System.out.println(xmlDoc.select("employee"));

输出:

<employee> 
 <name>
  membersound
 </name> 
 <id>
  30
 </id> 
</employee>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM