Forum > Networking and Web Programming
xquery: How to load HTML string?
(1/1)
JR2Media:
Is it possible to load a HTML string using xquery in benibela's InternetTools? I can't find anything in the documentation, or online. I've tried the following:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---xqvalue(Response.DataString).map('//title').toString;
But this produces an error:
--- Quote ---Need context item that is a node to get root element
--- End quote ---
Using debugger I can see that string being passed into xqvalue is HTML.
BeniBela:
xqvalue only loads a string. It was supposed to be used with an url like
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---xqvalue(url).retrieve().map('//title').toString
To convert the string to a document, the html parser needs to be called. There is a function x:parse-html for that. And it cannot be called in map.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---xqvalue(Response.DataString).query('x:parse-html($_)//title').toString
There is the legacy function process in simpleinternet, which guesses if the string is an url or xml or json. But it might be confusing to debug if it guesses wrong
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---process(Response.DataString, '//title').toString
Navigation
[0] Message Index