Thread: [xmljs-users] xml and javascript problem.
Brought to you by:
djoham,
witchhunter
From: Tun L. <ch...@si...> - 2004-08-02 02:50:37
Attachments:
biblio.html
|
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" = "http://www.w3.org/TR/html4/strict.dtd">=0A= <html>=0A= <head>=0A= <title></title>=0A= <script>=0A= var arrTags =3D new Array();=0A= var uarrTags =3D new Array();=0A= var strContent =3D "";=0A= var ie =3D (typeof window.ActiveXObject !=3D 'undefined');=0A= var moz =3D (typeof document.implementation !=3D 'undefined') && =0A= (typeof document.implementation.createDocument !=3D 'undefined');=0A= var xmlDoc; =0A= function importXML(file) {=0A= if (moz) { =0A= xmlDoc =3D document.implementation.createDocument("", "doc", null);=0A= xmlDoc.onload =3D readXML;=0A= xmlDoc.load(file);=0A= } else if (ie) {=0A= xmlDoc =3D new ActiveXObject("Microsoft.XMLDOM");=0A= xmlDoc.async =3D false;=0A= while(xmlDoc.readyState !=3D 4) {}; =0A= xmlDoc.load(file);=0A= readXML();=0A= }=0A= }=0A= =0A= function readXML() {=0A= root =3D xmlDoc.documentElement;=0A= crawl(root, 0);=0A= uarrTags=3DfindUniqueTags(arrTags);=0A= for ( var i =3D 0; i < uarrTags.length; i++ ) {=0A= document.myform.field1.options[i].text =3D uarrTags[i];=0A= document.myform.field1.options[i].value =3D uarrTags[i];=0A= document.myform.field2.options[i].text =3D uarrTags[i];=0A= document.myform.field2.options[i].value =3D uarrTags[i];=0A= }=0A= if (document.getElementById) {=0A= //document.getElementById("content").innerHTML =3D strContent + = document.getElementById("content").innerHTML;=0A= // document.myform.example.options[0]=3DstrContent;=0A= } else if (document.all) {=0A= document.all["content"].innerHTML =3D strContent + = document.all["content"].innerHTML;=0A= document.myform.example.options[0]=3DstrContent;=0A= }=0A= }=0A= =0A= function crawl(node, level) {=0A= if (node.nodeType =3D=3D 3 && isEmptyNode(node.nodeValue)) {=0A= // Don't process empty text nodes in Mozilla (IE ignores them = anyway).=0A= } else {=0A= var indent =3D "";=0A= =0A= var index=3D0;=0A= for (var i =3D 0; i < level; i++) {=0A= //indent =3D indent + " ";=0A= }=0A= //strContent =3D strContent + "<p>";=0A= //strContent =3D strContent + indent + "attributes =3D " + = node.attributes + "<br/>";=0A= //strContent =3D strContent + indent + "childNodes =3D " + = node.childNodes + "<br/>";=0A= //strContent =3D strContent + indent + "firstChild =3D " + = node.firstChild + "<br/>";=0A= //strContent =3D strContent + indent + "lastChild =3D " + = node.lastChild + "<br/>";=0A= //strContent =3D strContent + indent + "nextSibling =3D " + = node.nextSibling + "<br/>";=0A= //strContent =3D strContent + indent + "nodeName =3D " + = node.nodeName + "<br/>";=0A= strContent =3D strContent + node.nodeName + "<br/>";=0A= var n =3D node.nodeName;=0A= var tokenizer =3D n.split(":")=0A= if(n!=3D"#text")=0A= {=0A= arrTags.push(tokenizer[1]);=0A= }=0A= //if(strContent.equals("rdf:RDF"))=0A= //{=0A= //strContent =3D strContent;=0A= //}=0A= =0A= //index++;=0A= //arrTags.add(strContent); =0A= //document.myform.example.options[0]=3DstrContent;=0A= //strContent =3D strContent + indent + "nodeType =3D " + = node.nodeType + "<br/>";=0A= //strContent =3D strContent + indent + "nodeValue =3D " + = node.nodeValue + "<br/>";=0A= //strContent =3D strContent + indent + "ownerDocument =3D " + = node.ownerDocument + "<br/>";=0A= //strContent =3D strContent + indent + "parentNode =3D " + = node.parentNode + "<br/>";=0A= //strContent =3D strContent + indent + "previousSibling =3D " + = node.previousSibling + "<br/>";=0A= if (node.attributes) {=0A= if (node.attributes.length > 0) {=0A= for (var i =3D 0; i < node.attributes.length; i++) {=0A= attribute =3D node.attributes.item(i);=0A= //strContent =3D strContent + indent + = " " + "attribute name =3D " + attribute.name + = "<br/>";=0A= //strContent =3D strContent + indent + = " " + "attribute specified =3D " + = attribute.specified + "<br/>";=0A= //strContent =3D strContent + indent + = " " + "attribute value =3D " + attribute.value + = "<br/>";=0A= }=0A= }=0A= }=0A= }=0A= =0A= if (node.firstChild) {=0A= crawl(node.firstChild, level + 1);=0A= }=0A= if (node.nextSibling) {=0A= crawl(node.nextSibling, level);=0A= }=0A= strContent =3D strContent + "</p>";=0A= }=0A= =0A= function findUniqueTags(arrAllTags) { =0A= =0A= var arrUniqueTags =3D new Array();=0A= var tagsPresentCounter =3D 0; =0A= =0A= for (i=3D0; i<arrAllTags.length; i++) { =0A= =0A= var foundIt =3D false; =0A= =0A= for (j=3D0; j<arrUniqueTags.length; j++) {=0A= if (arrUniqueTags[j] =3D=3D arrAllTags[i]) { foundIt =3D true; break; } = } =0A= =0A= if (foundIt !=3D true) { =0A= =0A= //Meaning it's not already in tagsPresent =0A= =0A= arrUniqueTags[tagsPresentCounter] =3D arrAllTags[i]; = tagsPresentCounter++; } =0A= =0A= } =0A= =0A= return arrUniqueTags; =0A= =0A= } =0A= =0A= function isEmptyNode(arg) {=0A= reg =3D /\n/g;=0A= arg =3D arg.replace(reg, "");=0A= reg =3D / /g;=0A= arg =3D arg.replace(reg, "");=0A= if (arg.length =3D=3D 0) {=0A= return true;=0A= }=0A= return false;=0A= }=0A= =0A= </script>=0A= </head>=0A= <body onLoad=3D"importXML('biblio.rdf');"> =0A= =0A= =0A= <p>This is a more "real life" example, powered by a single XQuery = script.</p>=0A= =0A= <p>The sample collection contains 71098 book description (in RDF/XML)=0A= taken from our local university library.</p>=0A= =0A= <form action=3D"biblio.xq" method=3D"GET" name=3D"myform">=0A= =0A= <table width=3D"90%" cellpadding=3D"5" cellspacing=3D"0" = border=3D"0" bgcolor=3D"#EEEEEE">=0A= <tr bgcolor=3D"#99CCFF">=0A= <th width=3D"20%" align=3D"left">=0A= Search in=0A= </th>=0A= <th width=3D"40%" align=3D"left">=0A= Search what=0A= </th>=0A= <th width=3D"20%" align=3D"left">=0A= Interpret as=0A= </th>=0A= <th width=3D"20%" align=3D"left">=0A= </th>=0A= </tr>=0A= <tr>=0A= <td width=3D"20%" align=3D"left">=0A= <select name=3D"field1" size=3D"1">=0A= <option value=3D"any" selected=3D"true">Any</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= </select>=0A= </td>=0A= <td width=3D"40%" align=3D"left">=0A= <input type=3D"text" name=3D"term1" size=3D"30" />=0A= </td>=0A= <td width=3D"20%" align=3D"left">=0A= <select name=3D"mode1" size=3D"1">=0A= <option value=3D"near">near</option>=0A= <option value=3D"exact">exact match</option>=0A= <option value=3D"contains" selected=3D"true">word list</option>=0A= </select>=0A= </td>=0A= <td width=3D"20%" align=3D"left">=0A= <select name=3D"operator" size=3D"1">=0A= <option value=3D"or" selected=3D"true">or</option>=0A= <option value=3D"and" selected=3D"false">and</option>=0A= </select>=0A= </td>=0A= </tr>=0A= <tr>=0A= <td width=3D"20%" align=3D"left">=0A= <select name=3D"field2" size=3D"1">=0A= <option value=3D"any" selected=3D"true">Any</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"su">Subject</option>=0A= <option value=3D"au">Creator,Editor</option>=0A= <option value=3D"ti">Title</option>=0A= <option value=3D"ab">Description</option>=0A= </select>=0A= </td>=0A= <td width=3D"40%" align=3D"left">=0A= <input type=3D"text" name=3D"term2" size=3D"30" />=0A= </td>=0A= <td width=3D"20%" align=3D"left">=0A= <select name=3D"mode2" size=3D"1">=0A= <option value=3D"near">near</option>=0A= <option value=3D"exact">exact match</option>=0A= <option value=3D"contains" selected=3D"true">word list</option>=0A= </select>=0A= </td>=0A= <td width=3D"20%" align=3D"left">=0A= </td>=0A= </tr>=0A= <tr>=0A= <td align=3D"left" valign=3D"center" colspan=3D"3">=0A= <select name=3D"howmany" size=3D"1">=0A= <option>15</option>=0A= <option>30</option>=0A= <option>50</option>=0A= <option>100</option>=0A= </select>=0A= <small>hits will be displayed</small>=0A= </td>=0A= <td align=3D"left">=0A= <input type=3D"submit" />=0A= </td>=0A= </tr>=0A= </table>=0A= </form>=0A= =0A= <p><small>You may use wildcards *, ? and character ranges like = [a-zA-Z] =0A= for search terms</small></p>=0A= =0A= =0A= </body>=0A= =0A= |
From: David J. <dj...@ya...> - 2004-08-02 19:54:19
|
Hi Tun Lin, Since your question doesn't directly relate to XML for <SCRIPT>, I can only guess as to what the problem is. I'm guessing that you're running into a security problem loading the file. Your JavaScript or HTML probably thinks that the file you're trying to load is not from its originating domain when you're connect to localhost. When you're connected via a mount point, it thinks your OK. Why this is, I'm not sure :( The only thing I can think of is to go google for some examples of how this works. You might also want to look at the Sarissa project on SourceForge for some help. The Sarissa project is a wrapper around the various browser's DOM implementations. The URL for the project is https://sourceforge.net/projects/sarissa/ Good luck! David --- Tun Lin <ch...@si...> wrote: > > Hi everyone, > > I am trying xml dom in javascript in html file but I have a problem. This is because when I try > a html with javascript as attached on localhost, it is unable to run properly. However, if I > just double click on the file, it is able to run properly. > > Can anyone help, please? > > Regards, > > Tun Lin. --------------------------------- 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); readXML(); }}function readXML() { root = xmlDoc.documentElement; crawl(root, 0); uarrTags=findUniqueTags(arrTags);for ( var i = 0; i "; //strContent = strContent + indent + "attributes = " + node.attributes + " "; //strContent = strContent + indent + "childNodes = " + node.childNodes + " "; //strContent = strContent + indent + "firstChild = " + node.firstChild + " "; //strContent = strContent + indent + "lastChild = " + node.lastChild + " "; //strContent = strContent + indent + "nextSibling = " + node.nextSibling + " "; //strContent = strContent + indent + "nodeName = " + node.nodeName + " "; strContent = strContent + node.nodeName + " ";var n = node.nodeName;var tokenizer = n.split(":")if(n!="#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 + " "; //strContent = strContent + indent + "nodeValue = " + node.nodeValue + " "; //strContent = strContent + indent + "ownerDocument = " + node.ownerDocument + " "; //strContent = strContent + indent + "parentNode = " + node.parentNode + " "; //strContent = strContent + indent + "previousSibling = " + node.previousSibling + " "; if (node.attributes) { if (node.attributes.length > 0) { for (var i = 0; i "; //strContent = strContent + indent + " " + "attribute specified = " + attribute.specified + " "; //strContent = strContent + indent + " " + "attribute value = " + attribute.value + " "; } } } } if (node.firstChild) { crawl(node.firstChild, level + 1); } if (node.nextSibling) { crawl(node.nextSibling, level); } strContent = strContent + " ";}function findUniqueTags(arrAllTags) { var arrUniqueTags = new Array();var tagsPresentCounter = 0; for (i=0; i This is a more "real life" example, powered by a single XQuery script. The sample collection contains 71098 book description (in RDF/XML) taken from our local university library. Search in Search what Interpret as Any Creator,Editor Title Description Subject Creator,Editor Title Description Subject Subject Creator,Editor Title Description [input] near exact match word list or and Any Creator,Editor Title Description Subject Creator,Editor Title Description Subject Subject Creator,Editor Title Description [input] near exact match word list 15 30 50 100 hits will be displayed [input] You may use wildcards *, ? and character ranges like [a-zA-Z] for search terms |
From: Tun L. <ch...@si...> - 2004-08-03 00:59:22
|
Hi David, It seems that the code that I have is unable to read the rdf file that I want to import using javascript, thus causing the object not found error. Is there something missing in the web.xml file in eXist that I am using? Is there some configuration to be done? Hope to hear from you soon. ----- Original Message ----- From: "David Joham" <dj...@ya...> To: "Tun Lin" <ch...@si...>; <xml...@li...> Sent: Tuesday, August 03, 2004 3:54 AM Subject: Re: [xmljs-users] xml and javascript problem. > Hi Tun Lin, > > Since your question doesn't directly relate to XML for <SCRIPT>, I can only guess as to what the > problem is. I'm guessing that you're running into a security problem loading the file. Your > JavaScript or HTML probably thinks that the file you're trying to load is not from its originating > domain when you're connect to localhost. When you're connected via a mount point, it thinks your > OK. > > Why this is, I'm not sure :( The only thing I can think of is to go google for some examples of > how this works. You might also want to look at the Sarissa project on SourceForge for some help. > The Sarissa project is a wrapper around the various browser's DOM implementations. The URL for the > project is https://sourceforge.net/projects/sarissa/ > > > Good luck! > > > David > > --- Tun Lin <ch...@si...> wrote: > > > > > Hi everyone, > > > > I am trying xml dom in javascript in html file but I have a problem. This is because when I try > > a html with javascript as attached on localhost, it is unable to run properly. However, if I > > just double click on the file, it is able to run properly. > > > > Can anyone help, please? > > > > Regards, > > > > Tun Lin. > --------------------------------- > 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); readXML(); }}function readXML() { root = xmlDoc.documentElement; > crawl(root, 0); uarrTags=findUniqueTags(arrTags);for ( var i = 0; i "; //strContent = > strContent + indent + "attributes = " + node.attributes + " > "; //strContent = strContent + indent + "childNodes = " + node.childNodes + " > "; //strContent = strContent + indent + "firstChild = " + node.firstChild + " > "; //strContent = strContent + indent + "lastChild = " + node.lastChild + " > "; //strContent = strContent + indent + "nextSibling = " + node.nextSibling + " > "; //strContent = strContent + indent + "nodeName = " + node.nodeName + " > "; strContent = strContent + node.nodeName + " > ";var n = node.nodeName;var tokenizer = n.split(":")if(n!="#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 + " > "; //strContent = strContent + indent + "nodeValue = " + node.nodeValue + " > "; //strContent = strContent + indent + "ownerDocument = " + node.ownerDocument + " > "; //strContent = strContent + indent + "parentNode = " + node.parentNode + " > "; //strContent = strContent + indent + "previousSibling = " + node.previousSibling + " > "; if (node.attributes) { if (node.attributes.length > 0) { for (var i = 0; i "; > //strContent = strContent + indent + " " + "attribute specified = " + attribute.specified > + " > "; //strContent = strContent + indent + " " + "attribute value = " + attribute.value + > " > "; } } } } if (node.firstChild) { crawl(node.firstChild, level + 1); } if > (node.nextSibling) { crawl(node.nextSibling, level); } strContent = strContent + " > ";}function findUniqueTags(arrAllTags) { var arrUniqueTags = new Array();var tagsPresentCounter = > 0; for (i=0; i > This is a more "real life" example, powered by a single XQuery script. > > The sample collection contains 71098 book description (in RDF/XML) taken from our local > university library. > Search in Search what > Interpret as Any Creator,Editor > Title Description Subject Creator,Editor Title Description > Subject Subject Creator,Editor Title Description > [input] near exact match word list > or and Any Creator,Editor > Title Description Subject Creator,Editor Title Description > Subject Subject Creator,Editor Title Description > [input] near exact match word list > 15 30 50 100 hits will be displayed > [input] > You may use wildcards *, ? and character ranges like [a-zA-Z] for search terms > > |
From: David J. <dj...@ya...> - 2004-08-03 15:34:24
|
Hi Tun Lin, I'm sorry, I really don't know. I've never worked with the browser's DOM directly in the manner you're trying. My only suggestion is to google the web for assistance. I know what you're trying to do is possible so there should be help available... Good luck! David --- Tun Lin <ch...@si...> wrote: > Hi David, > > It seems that the code that I have is unable to read the rdf file that I > want to import using javascript, thus causing the object not found error. Is > there something missing in the web.xml file in eXist that I am using? Is > there some configuration to be done? > > Hope to hear from you soon. > > ----- Original Message ----- > From: "David Joham" <dj...@ya...> > To: "Tun Lin" <ch...@si...>; <xml...@li...> > Sent: Tuesday, August 03, 2004 3:54 AM > Subject: Re: [xmljs-users] xml and javascript problem. > > > > Hi Tun Lin, > > > > Since your question doesn't directly relate to XML for <SCRIPT>, I can > only guess as to what the > > problem is. I'm guessing that you're running into a security problem > loading the file. Your > > JavaScript or HTML probably thinks that the file you're trying to load is > not from its originating > > domain when you're connect to localhost. When you're connected via a mount > point, it thinks your > > OK. > > > > Why this is, I'm not sure :( The only thing I can think of is to go > google for some examples of > > how this works. You might also want to look at the Sarissa project on > SourceForge for some help. > > The Sarissa project is a wrapper around the various browser's DOM > implementations. The URL for the > > project is https://sourceforge.net/projects/sarissa/ > > > > > > Good luck! > > > > > > David > > > > --- Tun Lin <ch...@si...> wrote: > > > > > > > > Hi everyone, > > > > > > I am trying xml dom in javascript in html file but I have a problem. > This is because when I try > > > a html with javascript as attached on localhost, it is unable to run > properly. However, if I > > > just double click on the file, it is able to run properly. > > > > > > Can anyone help, please? > > > > > > Regards, > > > > > > Tun Lin. > > --------------------------------- > > 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); readXML(); }}function readXML() { root = > xmlDoc.documentElement; > > crawl(root, 0); uarrTags=findUniqueTags(arrTags);for ( var i = 0; i "; > //strContent = > > strContent + indent + "attributes = " + node.attributes + " > > "; //strContent = strContent + indent + "childNodes = " + > node.childNodes + " > > "; //strContent = strContent + indent + "firstChild = " + > node.firstChild + " > > "; //strContent = strContent + indent + "lastChild = " + node.lastChild > + " > > "; //strContent = strContent + indent + "nextSibling = " + > node.nextSibling + " > > "; //strContent = strContent + indent + "nodeName = " + node.nodeName + > " > > "; strContent = strContent + node.nodeName + " > > ";var n = node.nodeName;var tokenizer = > n.split(":")if(n!="#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 + " > > "; //strContent = strContent + indent + "nodeValue = " + node.nodeValue > + " > > "; //strContent = strContent + indent + "ownerDocument = " + > node.ownerDocument + " > > "; //strContent = strContent + indent + "parentNode = " + > node.parentNode + " > > "; //strContent = strContent + indent + "previousSibling = " + > node.previousSibling + " > > "; if (node.attributes) { if (node.attributes.length > 0) > { for (var i = 0; i "; > > //strContent = strContent + indent + " " + "attribute specified = > " + attribute.specified > > + " > > "; //strContent = strContent + indent + " " + "attribute value > = " + attribute.value + > > " > > "; } } } } if (node.firstChild) { > crawl(node.firstChild, level + 1); } if > > (node.nextSibling) { crawl(node.nextSibling, level); } strContent = > strContent + " > > ";}function findUniqueTags(arrAllTags) { var arrUniqueTags = new > Array();var tagsPresentCounter = > > 0; for (i=0; i > > This is a more "real life" example, powered by a single XQuery script. > > > > The sample collection contains 71098 book description (in RDF/XML) taken > from our local > > university library. > > Search in Search > what > > Interpret as Any > Creator,Editor > > Title Description Subject Creator,Editor Title > Description > > Subject Subject Creator,Editor Title > Description > > [input] near exact match word > list > > or and Any > Creator,Editor > > Title Description Subject Creator,Editor Title > Description > > Subject Subject Creator,Editor Title > Description > > [input] near exact match word list > > 15 30 50 100 hits will be displayed > > [input] > > You may use wildcards *, ? and character ranges like [a-zA-Z] for > search terms > > > > > > |