[erlang-questions] UTF-8 problems

Dustin Whitney <>
Mon Feb 4 07:11:13 CET 2008


Hello,
    I want to make an HTTP GET request to a URL that returns an XML
document, which I'd then like to run an XPath query against, but when I run
it, all I get is a list of integers when I output the response body.  I
think this is due to the charset being in UTF-8.  When I run the same
program against http://slashdot.org, I get back the html content from
slashdot in a readable form, and I think it's because slashdot
uses iso-8859-1 as it's charset.  How can I run XPath against what is
returned when the page uses UTF-8?  And how can I print UTF-8 to the
console, so I can actually read it?  Here is the small script I've written:

-module(tmp).
-export([get_url/0]).

get_url() ->
{_,{_, Header, Body}} = http:request("
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&should-sponge=&query=PREFIX+xsd%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0D%0APREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+dbpedia2%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fproperty%2F%3E%0D%0A%0D%0ASELECT+*+WHERE+%7B%0D%0A%3Fsubject+rdf%3Atype+%3Chttp%3A%2F%2Fdbpedia.org%2Fclass%2Fyago%2FCity108524735%3E.%0D%0A%3Fsubject+rdfs%3Alabel+%3Flabel.%0D%0A%3Fsubject+dbpedia2%3Apopulation+%3Fpopulation.%0D%0AFILTER+%28lang%28%3Flabel%29+%3D+%22en%22+%26%26+xsd%3Ainteger%28%3Fpopulation%29+%3E+200000%29%0D%0A%7D&format=application%2Fsparql-results+xml&debug=on
"),
Body.


I appreciate any help.  Thanks,
Dustin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080204/4f5dcc97/attachment.html>


More information about the erlang-questions mailing list