Мой оригинальный xml файл:
</Toto>
<Ride>5</Ride>
</Toto>
<Document>
<a>
<b>1234</b>
<c>foo</c>
<d>bar</d>
</a>
<Document>
Я хочу изменить 1234
на 5678
.
File f = new File(filePath);
Document doc = Jsoup.parse(new FileInputStream(f), "UTF-8", f.getAbsolutePath(), Parser.xmlParser());
Element elem = doc.select("Document > a > b").first();
TextNode tn = elem.textNodes().get(0);
tn.replaceWith(new TextNode("5478"));
value = doc.toString();
Мой вывод - файл xlm:
</Toto>
<Ride>
5
</Ride>
</Toto>
<Document>
<a>
<b>
5478
</b>
<c>
foo
</c>
<d>
bar
</d>
</a>
<Document>