How to tweak this javascript file to read in my data on localhost. parsing RDF task

I'm using this Javascript RDF parser.

In the documentation it says to use it accordingly:

Downloads and parses RDF from a url. url is the url to recieve the RDF from, use the full url, not a relative one, or the base url will be wrong. func is a javascript function to call when the rdf has been processed.

In the file for the parser, I spied this empty variable:

    var baseURL='';

and I filled it up like so:

    var baseURL='http://localhost:8888/demo/StackOverflow-Europe.rdf';

In my index.html file I tried to call this parsing script in this way:

<!DOCTYPE html>
<meta charset='utf-8'>
    <script src="" charset="utf-8"></script>
    <link rel='stylesheet' href='style.css'>
    <script type='text/javascript' src='script.js'></script>

    <script type='text/javascript' src='parser.js'></script>


but finally... nothing happened.

What am I doing wrong?

I guess that's not the right way to call javascript files? Is that it? Or maybe there's another reason.

I'm not so familiar with Javascript.



As Jeen Broekstra said in the comments, the line you use in your html file:

<script type='text/javascript' src='parser.js'></script>

has to only purpose to load the the rdf-parser library.

You can load it directly on the main server

<script src=""></script>

and use your own script.

You can use the official demo as a starter point:

<script type="text/javascript">
 function demo() {
     foafNS = "";
     myRDF  = new RDF();
     myRDF.getRDFURL('/foaf2.rdf', callback);
     function callback() {
         alert(" contains the following triples\n\n" + myRDF.toNTriples())
         nm   = myRDF.Match(null, null, foafNS + "name", "Jim Ley")
         mbox = myRDF.getSingleObject(null, nm[0].subject, foafNS + "mbox", null)
         alert("The e-mail address of Jim Ley is " + mbox)
  document.write('<p>See demo using <a href="/foaf2.rdf">/foaf2.rdf</a> &nbsp; &nbsp; <button onclick="demo()">See Demo</button></p>')
  • new RDF() allows you to create an RDF utility object
  • getRDFURL('/foaf2.rdf', callback) loads the foaf2.rdf file and set the function callback as a callback, i.e. this function is called when the rdf file has been completely loaded.
  • myRDF.toNTriples() returns all RDF triples.
  • nm = myRDF.Match(null, null, foafNS + "name","Jim Ley") returns an array of triples that match the subject/predicate/object pattern.
  • mbox = myRDF.getSingleObject(null, nm[0].subject, foafNS + "mbox", null) returns the value of the object in the collection of triples that matches the subject/predicate/object pattern, or an empty string if not found.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.