Hi there,
sorry if this a long post but I'm really just starting out. I've been
using MSXML to parse an OWL but would like to use a different
solution. Basically it reads the OWL (Based on XML) and puts values in
a number of arrays and then puts the contents of the array in a HTML
table. I'd like to keep the array structure. I've checked out all
sorts of different javascript parsers but have not met with a great
deal of success with any of them and I'd be grateful for any advice.
I'll include the two files below and would be grateful for any advice.
Thanks in advance,
Dom
--HTML File--
<!-- Start of document -->
<html>
<head>
<title>Using MSXML to look through the Ontology</title>
<script type="text/javascript">
/* Once you have installed IE, the parser is available to
scripts, both inside HTML documents and inside
ASP files. The parser features a language-neutral programming
model that supports:
+ JavaScript, VBScript, Perl, VB, Java, C++ and more
+ W3C XML 1.0 and XML DOM
+ DTD and validation */
var xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
/* Actually, just the last two lines of the function are enough
to load the XML file. The previous two
lines are written to ensure that the JavaScript functions
that we may use later to manipulate the XML
file data, does not perform any function on an uninitialized
object. Thus the function verify is
called.*/
function loadXML(xmlFile )
{
/* By default, the loading and parsing of an XML file occurs
asynchronously. To load the XML file
synchronously, set the async property to False. This forces
the loading of the entire XML document
before processing continues.*/
xmlDoc.async="f alse";
// See below
xmlDoc.onreadys tatechange=veri fy;
// Now load the file
xmlDoc.load(xml File);
// Gives us a nice name to use in subsequent code
xmlObj=xmlDoc.d ocumentElement;
}
function verify()
{
/* LOADING (1) The load is in progress—readin g persisted
properties, but not yet parsing data. For
readyState definitions, data should be considered
equivalent to binary large object (BLOB)
properties.
LOADED (2) Reading of the persisted properties
completed—readi ng and parsing data, but the object
model is not yet available.
INTERACTIVE (3) Some data has been read and parsed, and the
object model is now available on the
partially retrieved data set. Although the object model is
available during this state, it is
read-only.
COMPLETED (4) The document has been completely loaded,
successfully or unsuccessfully. */
if (xmlDoc.readySt ate != 4)
{
return false;
}
}
// Gets the specified element content from a collection of
elements
function getElementConte nt(marker, contents)
{
for(b=0; b<marker.length ; b++)
{
if(marker(b).ta gName==contents )
{
return marker(b).first Child.text;
}
}
}
// Gets the specified attribute content from a specified element
from a collection of elements
function getAttributeCon tent(marker, contents, element)
{
for(b=0; b<marker.length ; b++)
{
if(marker(b).ta gName==contents )
{
return marker(b).getAt tribute(element );
}
}
}
// Doesn't matter what the file is called, either XML or OWL
will do.
loadXML("NHSTru st.owl");
/* We'll construct 5 new arrays with the index having the same
number for each employee, this seems the
easiest way in which to access the pertinent data from the
XML file and we'll work on this data
rather than the file itself.*/
var eID=new Array();
var ename=new Array();
var etitle=new Array();
var edetails=new Array();
var esupID=new Array();
// Initialize the index for the five arrays created above
var f=0;
// Work through the whole document but...
for(a=0; a<xmlObj.childN odes.length; a++)
{
// ...filter out the employee elements and work on them.
if(xmlObj.child Nodes(a).tagNam e=="employee")
{
// Just to make life easier for us
var xmlWorking=xmlO bj.childNodes(a );
eID[f]=xmlWorking.get Attribute("rdf: ID");
ename[f]=getElementCont ent(xmlWorking. childNodes,"nam e");
etitle[f]=getElementCont ent(xmlWorking. childNodes, "title");
edetails[f]=getElementCont ent(xmlWorking. childNodes,
"details");
esupID[f]=getAttributeCo ntent(xmlWorkin g.childNodes,
"superior", "rdf:resource") ;
// Increment "f" so that we can add the next employee's data
f++;
}
}
// This converts the information from the above arrays into a
pretty table
// Used merely to make the following code less verbose
var h=" style=\"text-align: left; vertical-align: top;
white-space: nowrap;\">";
document.write( "<table style=\"text-align: left; width: 100%;\"
border=\"1\" cellspacing=\"2 \"");
document.write( "cellpadding=\" 2\">");
document.write( "<thead><tr><th "+h+"ID</th><th"+h+"Name </th><th"+h+"Titl e</th><th"+h+"Cont act
Details");
document.write( "</th><th"+h+"Supe rior's ID</th>");
document.write( "</tr></thead><tbody>") ;
for(g=0;g<eID.l ength;g++)
{
document.write( "<tr><td"+h );
document.write( eID[g]);
document.write( "</td><td"+h);
document.write( ename[g]);
document.write( "</td><td"+h);
document.write( etitle[g]);
document.write( "</td><td"+h);
document.write( edetails[g]);
document.write( "</td><td"+h);
document.write( esupID[g]);
document.write( "</td></tr>");
}
document.write( "</tbody></table>");
</script>
</head>
<!-- Empty body as the code gives the page its contents -->
<body/>
</html>
<!-- End of Document -->
--OWL File--
<?xml version="1.0"?>
<rdf:RDF xmlns="http://a.com/ontology#"
xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="htt p://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http ://www.w3.org/2002/07/owl#"
xml:base="http://a.com/ontology">
<owl:Ontology rdf:about=""/>
<owl:Class rdf:ID="employe e"/>
<owl:ObjectProp erty rdf:ID="superio r">
<rdfs:comment>E mployee's superior</rdfs:comment>
<rdfs:domain rdf:resource="# employee"/>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
</owl:ObjectPrope rty>
<owl:DatatypePr operty rdf:ID="details ">
<rdfs:domain rdf:resource="# employee"/>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
<rdfs:comment>C ontact details of employee</rdfs:comment>
</owl:DatatypePro perty>
<owl:DatatypePr operty rdf:ID="title">
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
<rdfs:domain rdf:resource="# employee"/>
<rdfs:comment>T itle of employee</rdfs:comment>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
</owl:DatatypePro perty>
<owl:Functional Property rdf:ID="name">
<rdfs:comment>N ame of the employee</rdfs:comment>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
<rdfs:domain rdf:resource="# employee"/>
<rdfs:label xml:lang="en">C ontact details</rdfs:label>
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
</owl:FunctionalP roperty>
<employee rdf:ID="H_Wards _and_Day_Servic e_Manager">
<name>Erik Straker</name>
<details>0122 3 604031</details>
<superior rdf:resource="# Area_Director_H untingdon"/>
<title>Wards & Day Service Manager</title>
</employee>
<employee rdf:ID="Area_Di rector_Huntingd on">
<details>0122 3 601298</details>
<superior rdf:resource="# Chief_Executive "/>
<name>Jessie Post</name>
<title>Area Director Huntingdon</title>
</employee>
<employee rdf:ID="Chief_E xecutive">
<details>0122 3 602600</details>
<title>Chief Executive</title>
<name>Eve Grindstaff</name>
<superior rdf:resource="# Chairman"/>
</employee>
<employee rdf:ID="Chairma n">
<details>0122 3 602301</details>
<name>Alejand ra Bizzell</name>
<title>Chairman </title>
</employee>
</rdf:RDF>
<!-- Created with Protege (with OWL Plugin 1.0, Build 72)
http://protege.stanford.edu -->
sorry if this a long post but I'm really just starting out. I've been
using MSXML to parse an OWL but would like to use a different
solution. Basically it reads the OWL (Based on XML) and puts values in
a number of arrays and then puts the contents of the array in a HTML
table. I'd like to keep the array structure. I've checked out all
sorts of different javascript parsers but have not met with a great
deal of success with any of them and I'd be grateful for any advice.
I'll include the two files below and would be grateful for any advice.
Thanks in advance,
Dom
--HTML File--
<!-- Start of document -->
<html>
<head>
<title>Using MSXML to look through the Ontology</title>
<script type="text/javascript">
/* Once you have installed IE, the parser is available to
scripts, both inside HTML documents and inside
ASP files. The parser features a language-neutral programming
model that supports:
+ JavaScript, VBScript, Perl, VB, Java, C++ and more
+ W3C XML 1.0 and XML DOM
+ DTD and validation */
var xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
/* Actually, just the last two lines of the function are enough
to load the XML file. The previous two
lines are written to ensure that the JavaScript functions
that we may use later to manipulate the XML
file data, does not perform any function on an uninitialized
object. Thus the function verify is
called.*/
function loadXML(xmlFile )
{
/* By default, the loading and parsing of an XML file occurs
asynchronously. To load the XML file
synchronously, set the async property to False. This forces
the loading of the entire XML document
before processing continues.*/
xmlDoc.async="f alse";
// See below
xmlDoc.onreadys tatechange=veri fy;
// Now load the file
xmlDoc.load(xml File);
// Gives us a nice name to use in subsequent code
xmlObj=xmlDoc.d ocumentElement;
}
function verify()
{
/* LOADING (1) The load is in progress—readin g persisted
properties, but not yet parsing data. For
readyState definitions, data should be considered
equivalent to binary large object (BLOB)
properties.
LOADED (2) Reading of the persisted properties
completed—readi ng and parsing data, but the object
model is not yet available.
INTERACTIVE (3) Some data has been read and parsed, and the
object model is now available on the
partially retrieved data set. Although the object model is
available during this state, it is
read-only.
COMPLETED (4) The document has been completely loaded,
successfully or unsuccessfully. */
if (xmlDoc.readySt ate != 4)
{
return false;
}
}
// Gets the specified element content from a collection of
elements
function getElementConte nt(marker, contents)
{
for(b=0; b<marker.length ; b++)
{
if(marker(b).ta gName==contents )
{
return marker(b).first Child.text;
}
}
}
// Gets the specified attribute content from a specified element
from a collection of elements
function getAttributeCon tent(marker, contents, element)
{
for(b=0; b<marker.length ; b++)
{
if(marker(b).ta gName==contents )
{
return marker(b).getAt tribute(element );
}
}
}
// Doesn't matter what the file is called, either XML or OWL
will do.
loadXML("NHSTru st.owl");
/* We'll construct 5 new arrays with the index having the same
number for each employee, this seems the
easiest way in which to access the pertinent data from the
XML file and we'll work on this data
rather than the file itself.*/
var eID=new Array();
var ename=new Array();
var etitle=new Array();
var edetails=new Array();
var esupID=new Array();
// Initialize the index for the five arrays created above
var f=0;
// Work through the whole document but...
for(a=0; a<xmlObj.childN odes.length; a++)
{
// ...filter out the employee elements and work on them.
if(xmlObj.child Nodes(a).tagNam e=="employee")
{
// Just to make life easier for us
var xmlWorking=xmlO bj.childNodes(a );
eID[f]=xmlWorking.get Attribute("rdf: ID");
ename[f]=getElementCont ent(xmlWorking. childNodes,"nam e");
etitle[f]=getElementCont ent(xmlWorking. childNodes, "title");
edetails[f]=getElementCont ent(xmlWorking. childNodes,
"details");
esupID[f]=getAttributeCo ntent(xmlWorkin g.childNodes,
"superior", "rdf:resource") ;
// Increment "f" so that we can add the next employee's data
f++;
}
}
// This converts the information from the above arrays into a
pretty table
// Used merely to make the following code less verbose
var h=" style=\"text-align: left; vertical-align: top;
white-space: nowrap;\">";
document.write( "<table style=\"text-align: left; width: 100%;\"
border=\"1\" cellspacing=\"2 \"");
document.write( "cellpadding=\" 2\">");
document.write( "<thead><tr><th "+h+"ID</th><th"+h+"Name </th><th"+h+"Titl e</th><th"+h+"Cont act
Details");
document.write( "</th><th"+h+"Supe rior's ID</th>");
document.write( "</tr></thead><tbody>") ;
for(g=0;g<eID.l ength;g++)
{
document.write( "<tr><td"+h );
document.write( eID[g]);
document.write( "</td><td"+h);
document.write( ename[g]);
document.write( "</td><td"+h);
document.write( etitle[g]);
document.write( "</td><td"+h);
document.write( edetails[g]);
document.write( "</td><td"+h);
document.write( esupID[g]);
document.write( "</td></tr>");
}
document.write( "</tbody></table>");
</script>
</head>
<!-- Empty body as the code gives the page its contents -->
<body/>
</html>
<!-- End of Document -->
--OWL File--
<?xml version="1.0"?>
<rdf:RDF xmlns="http://a.com/ontology#"
xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="htt p://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http ://www.w3.org/2002/07/owl#"
xml:base="http://a.com/ontology">
<owl:Ontology rdf:about=""/>
<owl:Class rdf:ID="employe e"/>
<owl:ObjectProp erty rdf:ID="superio r">
<rdfs:comment>E mployee's superior</rdfs:comment>
<rdfs:domain rdf:resource="# employee"/>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
</owl:ObjectPrope rty>
<owl:DatatypePr operty rdf:ID="details ">
<rdfs:domain rdf:resource="# employee"/>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
<rdfs:comment>C ontact details of employee</rdfs:comment>
</owl:DatatypePro perty>
<owl:DatatypePr operty rdf:ID="title">
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
<rdfs:domain rdf:resource="# employee"/>
<rdfs:comment>T itle of employee</rdfs:comment>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
</owl:DatatypePro perty>
<owl:Functional Property rdf:ID="name">
<rdfs:comment>N ame of the employee</rdfs:comment>
<rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
<rdfs:domain rdf:resource="# employee"/>
<rdfs:label xml:lang="en">C ontact details</rdfs:label>
<rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
</owl:FunctionalP roperty>
<employee rdf:ID="H_Wards _and_Day_Servic e_Manager">
<name>Erik Straker</name>
<details>0122 3 604031</details>
<superior rdf:resource="# Area_Director_H untingdon"/>
<title>Wards & Day Service Manager</title>
</employee>
<employee rdf:ID="Area_Di rector_Huntingd on">
<details>0122 3 601298</details>
<superior rdf:resource="# Chief_Executive "/>
<name>Jessie Post</name>
<title>Area Director Huntingdon</title>
</employee>
<employee rdf:ID="Chief_E xecutive">
<details>0122 3 602600</details>
<title>Chief Executive</title>
<name>Eve Grindstaff</name>
<superior rdf:resource="# Chairman"/>
</employee>
<employee rdf:ID="Chairma n">
<details>0122 3 602301</details>
<name>Alejand ra Bizzell</name>
<title>Chairman </title>
</employee>
</rdf:RDF>
<!-- Created with Protege (with OWL Plugin 1.0, Build 72)
http://protege.stanford.edu -->
Comment