![](/img/trans.png)
[英]Unable to check CDATA in XML using XMLEventReader in Stax
[英]unable to read CDATA in XML
我无法使用DOM4j库读取CDATA内容
<notes>
<note>
<![CDATA[
something
]]>
</note>
我正在尝试类似:
if(element.getName().equalsIgnoreCase("notes")){
List notes = element.elements();
for (int inotes = 0; inotes<notes.size(); inotes++) {
String content = ""; // ??????
}
}
您通过getStringValue获取CDATA内容
如果只有一个note元素:
String xml="<notes>\r\n" +
"\r\n" +
"<note>\r\n" +
"<![CDATA[\r\n" +
"qslkdfjqoisdèufç_rkjsdqfmlq_zds"+
"_èçé\"hc<<op<àç\">>>x>pciu\"éêù!x;%xkm<qknc"+
" something\r\n" +
"]]>\r\n" +
"</note></notes>";
// STRING => DOCUMENT
Document docu=DocumentHelper.parseText(xml);
// SELECT UNIQUE
Node nd=docu.selectSingleNode("//note");
// CONTENT
String value=nd.getStringValue();
System.out.println("VALUE="+value);
如果您有多个注释标签,请使用:
List<Node> notes = docu.selectNodes( "//note", "." ,true);
for (Node nd: notes)
{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.