【发布时间】:2015-11-14 16:08:50
【问题描述】:
我正在使用 JSoup 1.8.3 和 ColdFusion 10,并选择了一个 DOM element。我正在尝试调用ownText(),它不接受任何参数,我也没有给它任何参数,但我不断收到错误消息:
"没有找到ownText方法。要么没有方法 指定的方法名称和参数类型或 ownText 方法是 重载了 ColdFusion 无法破译的参数类型 可靠。 ColdFusion 找到 0 个与提供的匹配的方法 论据。如果这是一个 Java 对象并且您验证了该方法 存在,使用javacast函数减少歧义。”
错误文本表明问题可能会通过更清楚地转换参数来解决,但没有参数。我尝试将一个强制转换为 null,但这并没有解决问题。
如果我尝试调用 textNodes(),也会发生同样的错误。但是,我可以调用 text() 并且它返回的正是人们对调用的期望(我正在寻找的超集)。当我转储我正在调用的变量时,在调用之前,我看到它应该属于 org.jsoup.nodes.Element 类,并且我可以看到 ownText() 和 textNodes() 正确在应该可用的方法列表中,以及可以正常工作的 text() 。
为什么其中一些方法不起作用,我该如何访问它们?
代码示例:
<CFOUTPUT>
<cfset html = ' <html> ' >
<cfset html &= ' <head> <title> Bug Demo</title> </head> ' >
<cfset html &= ' <body><div class="wrapper" > ' >
<cfset html &= ' <div class="textSection" > ' >
<cfset html &= ' <h3><a href="http://example.com"> Undesired Link Text </a></h3> ' >
<cfset html &= ' This is the target text that the code below should extract.' >
<cfset html &= ' </div> ' >
<cfset html &= ' <div class="imageSection" > ' >
<cfset html &= ' <a href="http://example.com"><img src="/example.png"/></a> ' >
<cfset html &= ' </div> ' >
<cfset html &= ' </div> ' >
<cfset html &= '</body></html> '>
<cfscript>
//Load jSoup
paths = arrayNew(1);
paths[1] = expandPath("jsoup-1.8.3.jar");
loader = createObject("component", "colab.javaloader.javaloader.JavaLoader").init(paths);
jSoupClass = loader.create("org.jsoup.Jsoup");
//Parse document
dom = jSoupClass.parse(html);
wrapper = dom.select( JavaCast("string", "div.wrapper") ).first();
textSection = wrapper.select("div.textSection");
writeDump(textSection); //show type and methods of textSection
targetText = textSection.ownText(); //Error: method not found - ???
//targetText = textSection.ownText(JavaCast("null", "")); //also not found, but there should be no parameter
//textNodes = textSection.textNodes(); //Also not found
tooMuchInfo = textSection.text(); //works just fine
WriteOutput(tooMuchInfo);//produces "Undesired Link Text This is the target text that the code below should extract. "
</cfscript>
</CFOUTPUT>
输出看起来像这样,突出显示列出了所需的方法:
【问题讨论】:
-
你能提供有问题的例子吗?使用您尝试解析的 DOM 元素?
标签: java coldfusion jsoup