Tag: xml解析

如何从一段XML JAVA中抓取包装在CDATA标签中的文本内容

我有以下XML: application/xml local-C++ 200 <![CDATA[]]> 我想从内容节点解析出以下文本,如下所示: <![CDATA[]]> 注意这里的内容被包装在CDATA标签中。 我怎样才能用Java来完成这个任何方法。 这是我的代码: @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); } //输出:内容:空白 static String getDoOrchResponse(String xml, String tagFragment) throws FileNotFoundException { String content = new String(); try { […]