1
XML结构:JAXB解组CDATA HTML标记
<rep>
<text type="full">[!CDATA[Demo, <a href="http://www.google.com" target="_blank">Search</a> thank you]]</text>
</rep>
我能够解析使用JAXB这个XML,但结果是糟糕的,我已经使用@XmlValue
来获取文本元素值。
Java代码:
@XmlRootElement(name = "rep")
public class Demo {
@XmlElement(name = "text")
private Text text;
@Override
public String toString() {
return text.toString();
}
}
@XmlRootElement(name = "text")
public class Text {
@XmlValue
private String text;
@Override
public String toString() {
return "[text=" + text + "]";
}
}
输出:
[text= thank you]]]
但我需要得到这样的,例如:
[!CDATA[Demo, <a href="http://www.google.com" target="_blank">Search</a> thank you]]
或
Demo, <a href="http://www.google.com" target="_blank">Search</a> thank you
感谢,但这种情况下,我能不能够编辑XML,bcoz我从第三方API XML。有什么方法可以得到结果,除了我之外。 – RAjKuamr
@RAjKuamr - 我根据您的评论更新了我的答案。 –