[xmljs-users] xml and javascript problem.
Brought to you by:
djoham,
witchhunter
From: Tun L. <ch...@si...> - 2004-08-02 02:50:37
|
<!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= |