是否可以在java中使用xpath来获取包含HTML的cdata节点的内容 [英] Is it possible to use xpath in java to get the contents of a cdata node with HTML in it

查看:23
本文介绍了是否可以在java中使用xpath来获取包含HTML的cdata节点的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例...

<xml>
<level1>
<level2>
<![CDATA[ Release Date: 11/20/09 <br />View Trailer ]]>
</level2>
</level1>
</xml>

当我使用 inFeed.getXpath().evaluate("xml/level1/level2", myNodeList);

when I use inFeed.getXpath().evaluate("xml/level1/level2", myNodeList);

我收到发布日期:11/20/09 查看预告片"

I get "Release Date:11/20/09 View Trailer"

我的印象是,CDATA 的全部意义在于它保留了您想放入其中的任何笨拙的巨型文件.我是否使用了错误的 xpath 表达式?或者只是接近这一切都是错误的?

I was under the impression that the whole point of CDATA is that it preserves whatever mumbo jumbo you care to throw in there. Am I using the wrong xpath expression? or am just approaching this all wrong?

推荐答案

不知道我在做什么,但对我来说有什么不同

Not sure what I'm doing differently from you but for me

public class XpathFun
{
    public static void main(String[] args) throws Exception
    {
        String xml = "<xml><level1><level2><![CDATA[ Release Date: 11/20/09 <br />View Trailer ]]></level2></level1></xml>";
        InputSource inputSource = new InputSource(new ByteArrayInputStream(xml.getBytes()));
        System.out.println(XPathFactory.newInstance().newXPath().evaluate("xml/level1/level2", inputSource));
    }
}

结果:

Release Date: 11/20/09 <br />View Trailer 

这篇关于是否可以在java中使用xpath来获取包含HTML的cdata节点的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆