Recent

Author Topic: xquery: How to load HTML string?  (Read 1459 times)

JR2Media

  • New member
  • *
  • Posts: 9
xquery: How to load HTML string?
« on: May 18, 2021, 07:23:27 am »
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  [Select][+][-]
  1. xqvalue(Response.DataString).map('//title').toString;

But this produces an error:

Quote
Need context item that is a node to get root element

Using debugger I can see that string being passed into xqvalue is HTML.


BeniBela

  • Hero Member
  • *****
  • Posts: 793
    • homepage
Re: xquery: How to load HTML string?
« Reply #1 on: May 19, 2021, 08:20:16 pm »
xqvalue only loads a string. It was supposed to be used with an url like

Code: Pascal  [Select][+][-]
  1. 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  [Select][+][-]
  1. 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  [Select][+][-]
  1. process(Response.DataString, '//title').toString

 

TinyPortal © 2005-2018