CFML wrapper for JSoup.
Working with JSoup in CFML often requires JavaCasting variables and quite cumbersome syntax. This component provides some simpler CFML methods.
Assumes Jsoup is installed in your server class path.
-
Instantiate the component as a singleton in a shared scope, e.g. application
application.coldsoup = new coldSoup();
-
Call static methods as required, e.g.
myDoc = application.coldsoup.parse(html);
-
Return type from
parse()
is a Jsoup Document.These can be searched with
select(selector)
where selector is a JQuery-like selector, e.g.p.class
. The return value is sufficiently like a CF array to be used as one. Each element is a Jsoup Node. Modern versions of Jsoup should return an empty array if none are found. If you get null values, upgrade.
doc = coldSoup.parse(htmlDocument);
headings = doc.select("h2");
for (heading in headings) {...}
html = coldSoup.clean(html="<script>bad code</script> text", whitelist="basic" );
node = coldSoup.createNode("h2","my heading");
For further examples, see samples.