'Use jsoup to parse XML - prevent jsoup from "cleaning" <link> tags
In most case, I have no problem with using jsoup to parse XML. However, if there are <link> tags in the XML document, jsoup will change <link>some text here</link> to <link />some text here. This makes it impossible to extract text inside the <link> tag using CSS selector.
So how to prevent jsoup from "cleaning" <link> tags?
Solution 1:[1]
Do not store any text inside <link> element - it's invalid. If you need extra information, keep it inside HTML5 data-* attributes. I'm sure jsoup won't touch it.
<link rel="..." data-city="Warsaw" />
Solution 2:[2]
There can be a workaround for this. Before passing XML to jsoup. Transform XML file to replace all with some dummy tag say and do what you want to do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nowaker |
| Solution 2 | Vinay Lodha |
