java - JAXB unmarshalling CDATA with HTML tags -


xml structure:

<rep> <text type="full">[!cdata[demo, <a href="http://www.google.com" target="_blank">search</a> thank you]]</text> </rep> 

i can able parse xml using jaxb, result crappy, have used @xmlvalue text element value.

java code:

@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 + "]";     } } 

output:

[text= thank you]]] 

but need result this, eg:

[!cdata[demo, <a href="http://www.google.com" target="_blank">search</a> thank you]] 

or

demo, <a href="http://www.google.com" target="_blank">search</a> thank 

a cdata section starts <![cdata[ , ends ]>, xml document should be:

<rep> <text type="full"><![cdata[demo, <a href="http://www.google.com" target="_blank">search</a> thank you]]></text> </rep> 

example code

import java.io.file; import javax.xml.bind.*;  public class example {      public static void main(string[] args) throws exception {         jaxbcontext jc = jaxbcontext.newinstance(demo.class);          unmarshaller unmarshaller = jc.createunmarshaller();         file xsr = new file("src/forum16684040/input.xml");         demo demo = (demo) unmarshaller.unmarshal(xsr);          system.out.println(demo);     }  } 

output

[text=demo, <a href="http://www.google.com" target="_blank">search</a> thank you] 

update

thanks, case can't able edit xml, bcoz xml third party api. there way result, except.

you can use @xmlanyelement , specify domhandler keep dom content string. below link answer contains full example:


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -