В моем документе xml есть узел projectDetails, созданный из java jdom api, а данные внутри узлов поступают из базы данных.
Проблема связана с полем описания, которое хранится в виде html внутри базы данных. И когда я добавляюэто в элемент <descriptionDetails />
, и, преобразуя его с помощью класса преобразования Java, он экранирует все html-теги.
Возможно ли получить HTML-код, как и остальные теги, как потомков descriptionDetails и unescaped.
<projectDetails label="label.projectDetails">
<descriptionDetails label="label.descriptionDetails">
<html>
<head></head>
<body>
<strong><strong> Tiny MCE Bold<br /><em>Tiny MCE Bold/Itellic</em><br /><span style="text-decoration: underline;"><em>Tiny MCE Bold/Itellic/Underlined</em></span><br /></strong></strong>
<div>
Lorem Ipsum&nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
<br />
<br />
<span style="color: #ff0000;">printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset <span style="color: #ffffff; background-color: #808000;"><span style="background-color: #808000;">sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum,.</span><br /></span></span>
</div>
<h1>H1 heading</h1>
<h2>H1 heading</h2>
<h3>H1 heading</h3>
<h4>H1 heading</h4>
<h5>H1 heading</h5>
<h6>H1 heading<br /><br /><span style="font-size: 14pt;">font size 14</span></h6>
</body>
</html>
</descriptionDetails>
</projectDetails
private static String xmlAsString(Document xml) throws Exception {
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
Writer out = new StringWriter();
tf.transform(new DOMSource(xml), new StreamResult(out));
return out.toString();
}
Ожидаемый результат,
<projectDetails label="label.projectDetails">
<descriptionDetails label="label.descriptionDetails">
<html>
<head></head>
<body>
<strong><strong> Tiny MCE Bold<br /><em>Tiny MCE Bold/Itellic</em><br /><span style="text-decoration: underline;"><em>Tiny MCE Bold/Itellic/Underlined</em></span><br /></strong></strong>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
<br />
<br />
<span style="color: #ff0000;">printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset <span style="color: #ffffff; background-color: #808000;"><span style="background-color: #808000;">sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum,.</span><br /></span></span>
</div>
<h1>H1 heading</h1>
<h2>H1 heading</h2>
<h3>H1 heading</h3>
<h4>H1 heading</h4>
<h5>H1 heading</h5>
<h6>H1 heading<br /><br /><span style="font-size: 14pt;">font size 14</span></h6>
</body>
</html>
</descriptionDetails>
</projectDetails