<%@ LANGUAGE=JScript %> <% /* POSSIBLE MAIN (for testing purposes) */ // NOTE:it will be better if you read the documentation before you test the library // each significant function will print something on screen in order to help you to // understand how the code works, if this annoys you remove each line beginning with // "Response.write" // Loads document.xml var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0"); xmlDoc.async = false; xmlDoc.validateOnParse = false; xmlDoc.load(Server.mapPath("document.xml")); xmlDoc.setProperty("SelectionLanguage", "XPath"); // Xpointer expression // Note: the expresssion is not xpointer(expr) but expr directly, // check the string escaping if needed! var xpointerExpr=""; // res will yeld a location set (array of location) as result of the selectLocation // function selectLocations(doc, xpointer, cntxt) var res = selectLocation(xmlDoc, xpointerExpr, null); // ok do what you want with res... /* MAIN END */ function Point (node, index) { // A location of type point is defined by a node, called the container node, // and a non-negative integer, called the index. When the container node of // a point is of a node type that can have child nodes then the index is an // index into the child nodes, such a point is called a node-point. // When the container node of a point is of a node type that cannot have child // nodes then the index is an index into the characters of the string-value of // the node; such a point is called a character-point. var root=node.selectSingleNode("/"); if ((node.nodeTypeString == "element") || (node == root )) this.type = "node"; else this.type = "character"; this.containerNode = node; this.index = index; this.equals = pequals; } function pequals(point) { // Retrurns true if the two points are the same if ((this.type == point.type) && (this.containerNode == point.containerNode) && (this.index == point.index)) return true; else return false; } function Range (startPoint, endPoint) { // A location of type range is defined by two points, a start point and an end point. // A range represents all of the XML structure and content between the start point and end point. this.startPoint = startPoint; this.endPoint = endPoint; this.equals = requals; } function requals(range) { // Retrurns true if the two ranges are the same if ((this.startPoint.equals(range.startPoint)) && (this.endPoint.equals(range.endPoint))) return true; else return false; } function Location (type, loc) { // A location can be ethier a node, a point or a range this.type = type; if (type == "range") { this.startPoint = loc.startPoint; this.endPoint = loc.endPoint; } else if (type == "point") { this.pointType = loc.type; this.containerNode = loc.containerNode; this.index = loc.index; } else if (type == "node") { this.node = loc; } this.equals = lequals; } function lequals(loc) { // Retrurns true if the two locations are the same if ((loc != null) && (this.type == loc.type)) { switch (this.type) { case "range": if (this.startPoint.equals(loc.startPoint) && this.endPoint.equals(loc.endPoint)) return true; else return false; break; case "point": if ((this.pointType == loc.pointType) && (this.containerNode == loc.containerNode) && (this.indexe == loc.index)) return true; else return false; break; case "node": if (this.node == loc.node) return true; else return false; break; } } else return false; } function rangetst(ls) { // Test for range location type: returns the ranges in the location set ls Response.write("Range\n"); var result=new Array(); for (var i=0; i 0)) { // increments tindex (text index) tindex = tindex+textNodes[k].nodeValue.length; if ((tindex < pindex) || (tindex == pindex)) { tindexold = tindex; } else { if (tindex-(pindex+patt.length)>=0) { epoint = new Point (textNodes[k], pindex-tindexold+patt.length); // resets the pattern patt = ""; } else { if (spoint == null) { spoint = new Point(textNodes[k], pindex-tindexold) } // cuts the pattern patt = patt.substr(tindex-pindex); // increment pindex pindex = tindex; } tindexold = tindex; } k++; } if (spoint == null) spoint = new Point(epoint.containerNode, epoint.index-plen); // creates the location to return var range = new Range(spoint, epoint); var location = new Location("range", range); return location; } // calcLocation END function range(ls) { /* The range function returns ranges covering the locations in the argument location-set. For each location x in the argument location-set, a range location representing the covering range of x is added to the result location-set. -For a range location, the covering range is identical to the range. -For a point location, the start and end points of the covering range are the point itself. -For an attribute or namespace location, the container node of the start point and end point of the covering range is the attribute or namespace location; the index of the start point of the covering range is 0; and the index of the end point of the covering range is the length of the string-value of the attribute or namespace location. -For the root location, the container node of the start point and end point of the covering range is the root node; the index of the start point of the covering range is 0; and the index of the end point of the covering range is the number of children of the root location. -For any other kind of location, the container node of the start point and end point of the covering range is the parent of the location; the index of the start point of the covering range is the number of preceding sibling nodes of the location; and the index of the end point is one greater than the index of the start point. */ // result location set var result = new Array(); for (var i=0; i 0) && (!stop)) { Response.write("ST:"+xpointer+"TS\n"); var context = cloneArray(locationSet); var sublen=0; var tmp=xpointer.indexOf("|") var n=xpointer.search(keywords); if ((n>tmp) && (tmp!=-1)) n=tmp; if (n != -1) { if (xpointer.indexOf("point()") == n) { Response.write("POINT\n"); //xpath test (locationType) sublen=7; if (xpointer.charAt(n-1) == "/") { Response.write("PASSING:"+ xpointer.substr(0, n-1)+"\n"); locationSet=pointtst(selectLocations(doc, xpointer.substr(0, n-1), null)); } else { // Not abbreviated syntax: must cut '::' Response.write("PASSING:"+ xpointer.substr(0, n-2)+"\n"); locationSet=pointtst(selectLocations(doc, xpointer.substr(0, n-2), null)); } } else if (xpointer.indexOf("range()") == n) { Response.write("RANGE\n"); //xpath test (locationType) sublen=7; if (xpointer.charAt(n-1) == "/") { Response.write("PASSING:"+ xpointer.substr(0, n-1)+"\n"); locationSet=rangetst(selectLocations(doc, xpointer.substr(0, n-1), null)); } else { // Not abbreviated syntax: must cut '::' Response.write("PASSING:"+ xpointer.substr(0, n-2)+"\n"); locationSet=rangetst(selectLocations(doc, xpointer.substr(0, n-2), null)); } } else if (xpointer.indexOf("range-to") == n) { //xpointer function Response.write("RANGE-TO\n"); var arg = getArgument(xpointer.substr(n+8)); var parg = xpointer.substring(0,n-1); sublen = 8+arg.length+2; Response.write("ARG:"+arg+"GRA\n"); var ctx; if (parg != "") { Response.write("PARG:"+parg+"PGRA\n"); ctx = selectLocations(doc, parg, context); } else { Response.write("PARG era OKn"); ctx = context; } locationSet=rangeto(ctx, selectLocations(doc, arg, ctx)); } else if (xpointer.indexOf("range") == n) { //xpointer function Response.write("RANGE\n"); var arg = getArgument(xpointer.substr(n+5)); sublen = 5+arg.length+2; Response.write("ARG:"+arg+"GRA\n"); locationSet=range(selectLocations(doc, arg, null)); } else if (xpointer.indexOf("string-range") == n) { //xpointer function Response.write("STRING-RANGE\n"); var arg = getArgument(xpointer.substr(n+12)); //Response.write("ARG:"+arg+"GRA\n"); sublen=12+arg.length+2; var args = parseSRarg(arg); //just to see the arguments //for (var lm=0; lm