Retrieve value from CDATA

别来无恙 提交于 2019-12-11 01:18:21

问题


I am using java(JAXB) and i want to retrieve data from CDATA

<![CDATA[Need Help]]>

Desired output

Need Help

Can any body help me out. I tried several solutions.

Thanks!!


回答1:


try this

@XmlAccessorType(XmlAccessType.FIELD)
public class Test0 {
    String e1;

    public static void main(String[] args) throws Exception {
        String xml = "<root><e1><![CDATA[Need Help]]></e1></root>";
        Test0 t = JAXB.unmarshal(new StringReader(xml), Test0.class);
        System.out.println(t.e1);
    }
}

output

Need Help


来源:https://stackoverflow.com/questions/18206534/retrieve-value-from-cdata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!