I have a problem regarding javascript in
eXist.
As we all know Javascript is a client side scripting, why is the browser
unable to load xml document in javascript in eXist, giving me an error "object
required"? It seems it is unable to load the rdf document in javascript.
Can anyone help?
Below is a fragment of the code I used:
<script type="text/javascript">
<!--
var arrTags
= new Array();
var uarrTags = new Array();
var strContent = "";
var ie
= (typeof window.ActiveXObject != 'undefined');
var moz = (typeof
document.implementation != 'undefined') && (typeof
document.implementation.createDocument != 'undefined');
var xmlDoc;
function importXML(file)
{
if (moz)
{
xmlDoc = document.implementation.createDocument("",
"doc", null);
xmlDoc.onload =
readXML;
xmlDoc.load(file);
}
else if
(ie)
{
xmlDoc = new
ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async =
false;
while(xmlDoc.readyState != 4) {};
xmlDoc.load(file);
root =
xmlDoc.documentElement;
crawl(root, 0);
readXML();
}
}
function readXML()
{
root =
xmlDoc.documentElement;
crawl(root, 0);
uarrTags=findUniqueTags(arrTags);
for ( var i = 0; i <
uarrTags.length; i++ )
{
document.myform.field1.options[i].text =
uarrTags[i];
document.myform.field1.options[i].value =
uarrTags[i];
document.myform.field2.options[i].text =
uarrTags[i];
document.myform.field2.options[i].value = uarrTags[i];
}
//if (document.getElementById)
//{
//document.getElementById("content").innerHTML = strContent +
document.getElementById("content").innerHTML;
//document.myform.example.options[0]=strContent;
//}
//else if (document.all)
//{
//
document.all["content"].innerHTML = strContent +
document.all["content"].innerHTML;
//
document.myform.example.options[0]=strContent;
//}
}
function crawl(node,level){
var test =
node.nodeName;
if (node.nodeType == 3 /*Node.TEXT_NODE*/)
{
// Don't process empty text nodes in Mozilla (IE ignores
them anyway).
}
else
{
var
indent = "";
var index=0;
for (var i
= 0; i < level; i++)
{
//indent = indent +
" ";
}
//strContent = strContent +
"<p>";
//strContent = strContent + indent +
"attributes = " + node.attributes + "<br/>";
//strContent = strContent + indent + "childNodes = " + node.childNodes +
"<br/>";
//strContent = strContent + indent +
"firstChild = " + node.firstChild + "<br/>";
//strContent = strContent + indent + "lastChild = " + node.lastChild +
"<br/>";
//strContent = strContent + indent +
"nextSibling = " + node.nextSibling + "<br/>";
//strContent = strContent + indent + "nodeName = " + node.nodeName +
"<br/>";
strContent = strContent + node.nodeName +
"<br/>";
var no = node.nodeName;
var tokenizer =
no.split(":")
if(no!="#text")
{
arrTags.push(tokenizer[1]);
}
//if(strContent.equals("rdf:RDF"))
//{
//strContent = strContent;
//}
//index++;
//arrTags.add(strContent);
//document.myform.example.options[0]=strContent;
//strContent = strContent + indent + "nodeType = " + node.nodeType +
"<br/>";
//strContent = strContent + indent +
"nodeValue = " + node.nodeValue + "<br/>";
//strContent = strContent + indent + "ownerDocument = " + node.ownerDocument +
"<br/>";
//strContent = strContent + indent +
"parentNode = " + node.parentNode + "<br/>";
//strContent = strContent + indent + "previousSibling = " + node.previousSibling
+ "<br/>";
if (node.attributes)
{
if
(node.attributes.length > 0)
{
for (var i = 0; i <
node.attributes.length; i++)
{
attribute =
node.attributes.item(i);
//strContent = strContent + indent + " "
+ "attribute name = " + attribute.name +
"<br/>";
//strContent = strContent + indent + " "
+ "attribute specified = " + attribute.specified +
"<br/>";
//strContent = strContent + indent + " "
+ "attribute value = " + attribute.value +
"<br/>";
}
}
}
}
if (node.firstChild) {
crawl(node.firstChild, level + 1);
}
if (node.nextSibling)
{
crawl(node.nextSibling, level);
}
strContent = strContent + "</p>";
}
function findUniqueTags(arrAllTags)
{
var arrUniqueTags = new Array();
var tagsPresentCounter = 0;
for (i=0; i<arrAllTags.length; i++) {
var foundIt = false;
for (j=0; j<arrUniqueTags.length; j++) {
if
(arrUniqueTags[j] == arrAllTags[i]) { foundIt = true; break; } }
if (foundIt != true) {
//Meaning it's not already in tagsPresent
arrUniqueTags[tagsPresentCounter] = arrAllTags[i];
tagsPresentCounter++; }
}
return arrUniqueTags;
}
function isEmptyNode(arg)
{
reg = /\n/g;
arg = arg.replace(reg, "");
reg = / /g;
arg =
arg.replace(reg, "");
if (arg.length == 0)
{
return true;
}
return
false;
}
//-->
</script>
</head>
<body
onLoad="importXML('biblio.rdf');">