Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法读取XML格式的CDATA_Java_Xml_Cdata_Dom4j - Fatal编程技术网

Java 无法读取XML格式的CDATA

Java 无法读取XML格式的CDATA,java,xml,cdata,dom4j,Java,Xml,Cdata,Dom4j,我无法使用DOM4j库读取CDATA内容 <notes> <note> <![CDATA[ something ]]> </note> 我正在尝试类似的东西: if(element.getName().equalsIgnoreCase("notes")){ List notes = element.elements(); for (int inotes = 0; in

我无法使用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 = ""; // ??????
                }
            }
if(element.getName().equalsIgnoreCase(“notes”)){
列表注释=element.elements();

对于(int inotes=0;inotes您可以通过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);
String xml=“\r\n”+
“\r\n”+
“\r\n”+
“>>x>pciu\”êù!x;%xkm\r\n”+
"";
//字符串=>文档
Document docu=DocumentHelper.parseText(xml);
//选择唯一的
Node nd=docu.selectSingleNode(//注意);
//内容
String value=nd.getStringValue();
System.out.println(“VALUE=“+VALUE”);
如果有多个注释标记,请使用:

List<Node> notes = docu.selectNodes( "//note", "." ,true);
for (Node nd: notes)
    {
List notes=docu.selectNodes(//note“,”,true);
用于(节点nd:注释)
{

CDATA由XML解析器处理。只需选择元素的内容即可。