Jsoup 在该行显示所有 text()

Jsoup display all text() at the line

我原来的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>

能否请您在 toString() 之前尝试以下语句

doc.outputSettings().prettyPrint(false);

我也发现了几乎相同的问题How to convert Jsoup Document in a String without put spaces