java xml 获取cdata中内容,如何从一个XML JAVA中获取CDATA标记中包含的文本内容

本文介绍了在Java中解析XML时遇到的问题,即无法正确获取CDATA标记内的文本内容。通过展示代码片段,作者展示了尝试获取内容但得到空白结果的情况,并提出了使用getTextContent()方法和LSSerializer来解决这个问题。
摘要由CSDN通过智能技术生成

I have the following XML:

application/xml

local-C++

200

]]>

I'd like to parse out the following text from the content node as follows:

]]>

Notice here the content is wrapped in CDATA tags. How can I accomplish this in Java using any method.

Here is my code:

@Test

public void testGetDoOrchResponse() throws IOException {

String path = "/Users/haddad/Git/Tools/ContentUtils/src/test/resources/testdata/doOrch_testfiles/doOrch_response.xml";

File f = new File(path);

String response = FileUtils.readFileToString(f);

String content = getDoOrchResponse(response, "content");

System.out.println("Content: "+content);

}

// output: Content: blank

static String getDoOrchResponse(String xml,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值