How to get XML / RDF data from dbpedia link or url?
I recently tried to learn the Semantic Web. For a project I need to get data from a given dbPedia link. for example http://dbpedia.org/page/Berlin . But when you fetch data using java.net.URLConnection I am getting html data. How can I get the xml from the same link? I know there is a link on every dbpedia page to download the XML, but that is not what I want to do. Thanks in advance.
source to share
Note that the URI of the resource is actually http://dbpedia.org/resource/Berlin (with the resource , not the page ). Ideally, you can request a URI with an application Accept header / rdf + xml and get an RDF / XML representation of the resource. How the BBC publishes its data (see for example this answer ) but DBpedia doesn't. Even if you ask for application / rdf + xml, you get a redirect. You can see if you are trying with an HTTP client. For example, using the Advanced Rest Client in Chrome, we get this 303 redirect:
In the web browser, you are redirected to the version of the page with a 303 See Another response code. Ideally, you can request a resource URI with an accept header set to application / rdf + xml and get the data, but DBpedia doesn't fit pretty well.
So this means the easiest way is to note that at the bottom of http://dbpedia.org/page/Berlin there is a text with some download links
RDF ( N-Triples N3 / Turtle JSON XML )
The URL of the last link is http://dbpedia.org/data/Berlin.rdf . So you can get RDF / XML by changing the page or resource to data and adding .rdf to the end of the url. It's not the most efficient solution, but it looks like it's available.
source to share
A good way to access data from dbpedia is Sparql
. You can use Apache Jena to run requests Sparql
from http://dbpedia.org/sparql
source to share