Skip to content

Instantly share code, notes, and snippets.

@kognate
Created December 30, 2011 15:49
Show Gist options
  • Save kognate/1540374 to your computer and use it in GitHub Desktop.
Save kognate/1540374 to your computer and use it in GitHub Desktop.
prolog notes
use_module(library(http/http_client)).
use_module(library(http/http_open)).
use_module(library(xpath)).
http_open('http://www.codemash.org/rest/speakers', In, []),
load_xml_file(In,Out),
close(In).
http_open('http://www.codemash.org/rest/speakers', In, []),
copy_stream_data(In, user_output),
close(In).
http_open('http://www.codemash.org/rest/speakers', In, []),
load_xml_file(In,Out),
close(In),xpath(Out, //Name, Test).
load_html_file('t.html', Term),
xpath(Term,//h1,Test).
load_html_file('t.html', Term),
xpath(Term,//h1,element(h1,_,[T|X])).
load_xml_file('t.xml',Term),
xpath(Term,//Name,Test).
get_hone_from_file(Htmlfile, Hone) :- load_html_file('t.html', Term),xpath(Term,//h1,element(h1,_,[Hone|X])).
hones_in_html_file(Htmlfile, Z) :- setof(H,get_hone_from_file(Htmlfile,H),Z).
t.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Demo</title>
</head>
<body>
<h1 align=center>This is a demo</h1>
Paragraphs in HTML need not be closed.
<h1>anotther</h1>
This is called `omitted-tag' handling.
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment