Я использую JSoup 1.8.3 с ColdFusion 10 и выбрал DOM element. Я пытаюсь вызвать ownText(), который не принимает никаких аргументов, и я не придав ему любого, но я получаю сообщение об ошибке:Почему некоторые методы могут отсутствовать в JSoup?
"The ownText method was not found. Either there are no methods with the specified method name and argument types or the ownText method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity."
Текст ошибки показывает, что эта проблема может быть решена более четко отливка аргумента , но аргументов нет. Я попробовал добавить один приведение к нулевому, но это не устранило проблему.
Такая же ошибка возникает, если я пытаюсь вызвать textNodes(). Тем не менее, я могу вызвать text(), и он возвращает именно то, что можно было бы ожидать от вызова (надмножество того, что я ищу). Когда я выгружаю переменную, которую я вызываю, непосредственно перед вызовом, я вижу, что это класс org.jsoup.nodes.Element, как и должно быть, и я могу видеть как ownText(), так и textNodes() справа там в списке методов, которые должны быть доступны, наряду с текстом(), который отлично работает.
Почему некоторые из этих методов не работают, и как я могу получить к ним доступ?
Пример кода:
<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, который вы пытаетесь проанализировать? –