0

Having the following xml, how is possible to parse it without losing new line characters with Jsoup?

<datas>
    <data name="REG_NAME" type="S">OSS. EX ART_7</data>
    <data name="REG_NUM" type="I"></data>
    <data name="MOTIVATION" type="S">Test\ntest\ntest</data>
</datas>

Using the parser like this:

@Test
public void deserializeXml () {
    
    String xml = ""; // See the above snippet
    
    org.jsoup.nodes.Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    for (org.jsoup.nodes.Element e : doc.select("datas > data")) {
        String value = e.ownText();
        System.out.println(value);
    }
}

Doesn't work, the parser throws all the newline and add a blank space instead.

I cannot use Jsoup Settings or any pretty prints before or after because I'm starting with the correct String and I want to iterate each element of the Document generated by the Parser.

Is there a way to tell the parser just treat \n as a normal string?

Simone Lungarella
  • 177
  • 1
  • 3
  • 14

0 Answers0