Commit ac260306 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

More work and fixes on XPath:

- debugXML.c testXPath.c xpath.[ch]: More work on XPath/Xpointer,
  incorporated "(TOM)" <ptittom@free.fr> patches rebuilt the XPath
  examples with the extra test
Daniel
parent 7cfce324
Wed Oct 4 15:25:53 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* debugXML.c testXPath.c xpath.[ch]: More work on XPath/Xpointer,
incorporated "(TOM)" <ptittom@free.fr> patches rebuilt the XPath
examples with the extra test
Wed Oct 4 14:39:01 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.c xmlIO.c xmlIO.h: fixed bug 26650, and improved
......
......@@ -584,6 +584,8 @@ void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) {
xmlDebugDumpAttrList(output, node->properties, depth + 1);
if (node->type != XML_ENTITY_REF_NODE) {
if (node->content != NULL) {
shift[2 * i] = shift[2 * i + 1] = ' ' ;
shift[2 * i + 2] = shift[2 * i + 3] = 0 ;
fprintf(output, shift);
fprintf(output, "content=");
#ifndef XML_USE_BUFFER_CONTENT
......@@ -1681,6 +1683,18 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
case XPATH_STRING:
fprintf(stderr, "%s is a string\n", arg);
break;
case XPATH_POINT:
fprintf(stderr, "%s is a point\n", arg);
break;
case XPATH_RANGE:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_USERS:
fprintf(stderr, "%s is user-defined\n", arg);
break;
}
xmlXPathFreeNodeSetList(list);
} else {
......@@ -1719,6 +1733,18 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
case XPATH_STRING:
fprintf(stderr, "%s is a string\n", arg);
break;
case XPATH_POINT:
fprintf(stderr, "%s is a point\n", arg);
break;
case XPATH_RANGE:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_USERS:
fprintf(stderr, "%s is user-defined\n", arg);
break;
}
xmlXPathFreeNodeSetList(list);
} else {
......@@ -1761,6 +1787,18 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
case XPATH_STRING:
fprintf(stderr, "%s is a string\n", arg);
break;
case XPATH_POINT:
fprintf(stderr, "%s is a point\n", arg);
break;
case XPATH_RANGE:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_LOCATIONSET:
fprintf(stderr, "%s is a range\n", arg);
break;
case XPATH_USERS:
fprintf(stderr, "%s is user-defined\n", arg);
break;
}
xmlXPathFreeNodeSetList(list);
} else {
......
......@@ -51,7 +51,10 @@ typedef enum {
XPATH_BOOLEAN = 2,
XPATH_NUMBER = 3,
XPATH_STRING = 4,
XPATH_USERS = 5
XPATH_POINT = 5,
XPATH_RANGE = 6,
XPATH_LOCATIONSET = 7,
XPATH_USERS = 8
} xmlXPathObjectType;
typedef struct _xmlXPathObject xmlXPathObject;
......@@ -63,6 +66,9 @@ struct _xmlXPathObject {
double floatval;
xmlChar *stringval;
void *user;
int index;
void *user2;
int index2;
};
/*
......@@ -168,6 +174,11 @@ struct _xmlXPathContext {
/* extra variables */
int contextSize; /* the context size */
int proximityPosition; /* the proximity position */
/* extra stuff for XPointer */
int xptr; /* it this an XPointer context */
xmlNodePtr here; /* for here() */
xmlNodePtr origin; /* for origin() */
};
/*
......@@ -220,10 +231,13 @@ typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
/**
* Evaluation functions.
*/
void xmlXPathInit (void);
xmlXPathContextPtr xmlXPathNewContext (xmlDocPtr doc);
void xmlXPathFreeContext (xmlXPathContextPtr ctxt);
xmlXPathObjectPtr xmlXPathEval (const xmlChar *str,
xmlXPathContextPtr ctxt);
xmlXPathObjectPtr xmlXPathEvalXPtrExpr (const xmlChar *str,
xmlXPathContextPtr ctxt);
void xmlXPathFreeObject (xmlXPathObjectPtr obj);
xmlXPathObjectPtr xmlXPathEvalExpression (const xmlChar *str,
xmlXPathContextPtr ctxt);
......
========================
Expression: 1
Object is a number : 1
========================
Expression: 1+2
Object is a number : 3
========================
Expression: 2*3
Object is a number : 6
========================
Expression: 1+2*3+4
Object is a number : 11
========================
Expression: (1+2)*(3+4)
Object is a number : 21
========================
Expression: 0<1
Object is a Boolean : true
========================
Expression: 0<=1
Object is a Boolean : true
========================
Expression: 0>1
Object is a Boolean : false
========================
Expression: 0>=1
Object is a Boolean : false
========================
Expression: 1<0
Object is a Boolean : false
========================
Expression: 1<=0
Object is a Boolean : false
========================
Expression: 1>0
Object is a Boolean : true
========================
Expression: 1>=0
Object is a Boolean : true
========================
Expression: 1<1
Object is a Boolean : false
========================
Expression: 1<=1
Object is a Boolean : true
========================
Expression: 1>1
Object is a Boolean : false
========================
Expression: 1>=1
Object is a Boolean : true
========================
Expression: '0'<1
Object is a Boolean : true
========================
Expression: '0'<=1
Object is a Boolean : true
========================
Expression: '0'>1
Object is a Boolean : false
========================
Expression: '0'>=1
Object is a Boolean : false
========================
Expression: 0<'1.2'
Object is a Boolean : true
========================
Expression: 0<='1.2'
Object is a Boolean : true
========================
Expression: 0>'1.2'
Object is a Boolean : false
========================
Expression: 0>='1.2'
Object is a Boolean : false
========================
Expression: false()<1
Object is a Boolean : true
========================
Expression: false()<=1
Object is a Boolean : true
========================
Expression: 0>true()
Object is a Boolean : false
========================
Expression: 0>=true()
Object is a Boolean : false
========================
Expression: 1=1
Object is a Boolean : true
========================
Expression: 1!=1
Object is a Boolean : false
========================
Expression: 1=0
Object is a Boolean : false
========================
Expression: 1!=0
Object is a Boolean : true
========================
Expression: true()=true()
Object is a Boolean : true
========================
Expression: true()!=true()
Object is a Boolean : false
========================
Expression: true()=false()
Object is a Boolean : false
========================
Expression: false()!=true()
Object is a Boolean : true
========================
Expression: 'test'='test'
Object is a Boolean : true
========================
Expression: 'test'!='test'
Object is a Boolean : false
========================
Expression: 'test2'='test'
Object is a Boolean : false
========================
Expression: 'test2'!='test'
Object is a Boolean : true
========================
Expression: false()=0
Object is a Boolean : true
========================
Expression: false()!=0
Object is a Boolean : false
========================
Expression: false()=1
Object is a Boolean : false
========================
Expression: false()!=1
Object is a Boolean : true
========================
Expression: 0=true()
Object is a Boolean : false
========================
Expression: 0!=true()
Object is a Boolean : true
========================
Expression: 1=true()
Object is a Boolean : true
========================
Expression: 1!=true()
Object is a Boolean : false
========================
Expression: true()='test'
Object is a Boolean : true
========================
Expression: false()='test'
Object is a Boolean : false
========================
Expression: 'test'!=true()
Object is a Boolean : false
========================
Expression: 'test'!=false()
Object is a Boolean : true
========================
Expression: true()
Object is a Boolean : true
========================
Expression: false()
Object is a Boolean : false
========================
Expression: number("1.5")
Object is a number : 1.5
========================
Expression: concat("titi",'toto')
Object is a string : tititoto
========================
Expression: concat("titi",'toto',"tata","last")
Object is a string : tititototatalast
========================
Expression: string(5)
Object is a string : 5
========================
Expression: string(0.5)
Object is a string : 0.5
========================
Expression: string(-0.5)
Object is a string : -0.5
========================
Expression: string(true())
Object is a string : true
========================
Expression: string(false())
Object is a string : false
========================
Expression: concat("titi","toto")
Object is a string : tititoto
========================
Expression: concat("titi","toto","tata")
Object is a string : tititototata
========================
Expression: starts-with("tititoto","titi")
Object is a Boolean : true
========================
Expression: starts-with("tititoto","to")
Object is a Boolean : false
========================
Expression: contains("tititototata","titi")
Object is a Boolean : true
========================
Expression: contains("tititototata","toto")
Object is a Boolean : true
========================
Expression: contains("tititototata","tata")
Object is a Boolean : true
========================
Expression: contains("tititototata","tita")
Object is a Boolean : false
========================
Expression: substring("12345",2,3)
Object is a string : 234
========================
Expression: substring("12345",2)
Object is a string : 2345
========================
Expression: substring("12345",1.5,2.6)
Object is a string : 234
========================
Expression: substring("12345",0,3)
Object is a string : 12
========================
Expression: string-length("")
Object is a number : 0
========================
Expression: string-length("titi")
Object is a number : 4
========================
Expression: /child::EXAMPLE
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT EXAMPLE
ATTRIBUTE prop1
TEXT
content=gnome is great
content=gnome is great
ATTRIBUTE prop2
TEXT
content=& linux too
content=& linux too
========================
Expression: /child::*
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT EXAMPLE
ATTRIBUTE prop1
TEXT
content=gnome is great
content=gnome is great
ATTRIBUTE prop2
TEXT
content=& linux too
content=& linux too
========================
Expression: /child::EXAMPLE/child::head
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT head
========================
Expression: /child::EXAMPLE/child::*
Object is a Node Set :
Set contains 6 nodes:
1 ELEMENT head
......@@ -27,16 +39,28 @@ Set contains 6 nodes:
4 ELEMENT chapter
5 ELEMENT chapter
6 ELEMENT chapter
========================
Expression: /child::EXAMPLE/child::head/child::title
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT title
========================
Expression: /child::EXAMPLE/child::head/child::title/child::text()
Object is a Node Set :
Set contains 1 nodes:
1 TEXT
content=Welcome to Gnome
content=Welcome to Gnome
========================
Expression: /child::EXAMPLE/child::head/node()
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT title
========================
Expression: /descendant::title
Object is a Node Set :
Set contains 6 nodes:
1 ELEMENT title
......@@ -45,6 +69,9 @@ Set contains 6 nodes:
4 ELEMENT title
5 ELEMENT title
6 ELEMENT title
========================
Expression: /descendant::p/ancestor::chapter
Object is a Node Set :
Set contains 5 nodes:
1 ELEMENT chapter
......
========================
Expression: /following::*
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: /preceding::*
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: /child::EXAMPLE/preceding::*
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: /child::EXAMPLE/following::*
Object is a Node Set :
Set contains 0 nodes:
========================
Expression: /child::EXAMPLE/child::chapter[3]/preceding::*
Object is a Node Set :
Set contains 10 nodes:
1 ELEMENT p
2 ELEMENT title
3 ELEMENT chapter
4 ELEMENT p
5 ELEMENT image
ATTRIBUTE href
TEXT
content=linus.gif
6 ELEMENT p
7 ELEMENT title
8 ELEMENT chapter
9 ELEMENT title
10 ELEMENT head
========================
Expression: /child::EXAMPLE/child::chapter[3]/following::*
Object is a Node Set :
Set contains 6 nodes:
1 ELEMENT chapter
2 ELEMENT title
3 ELEMENT p
4 ELEMENT chapter
5 ELEMENT title
6 ELEMENT p
========================
Expression: /child::EXAMPLE/child::chapter[1]/image/preceding::*
Object is a Node Set :
Set contains 4 nodes:
1 ELEMENT p
2 ELEMENT title
3 ELEMENT title
4 ELEMENT head
========================
Expression: /child::EXAMPLE/child::chapter[1]/image/following::*
Object is a Node Set :
Set contains 13 nodes:
1 ELEMENT p
2 ELEMENT chapter
3 ELEMENT title
4 ELEMENT p
5 ELEMENT chapter
6 ELEMENT title
7 ELEMENT p
8 ELEMENT chapter
9 ELEMENT title
10 ELEMENT p
11 ELEMENT chapter
12 ELEMENT title
13 ELEMENT p
========================
Expression: //*[@id="root"]
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT EXAMPLE
ATTRIBUTE id
TEXT
content=root
content=root
ATTRIBUTE prop1
TEXT
content=gnome is great
content=gnome is great
ATTRIBUTE prop2
TEXT
content=& linux too
content=& linux too
========================
Expression: //*[@id="chapter2"]
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT chapter
ATTRIBUTE id
TEXT
content=chapter2
content=chapter2
========================
Expression: //*[@id="chapter5"]
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT chapter
ATTRIBUTE id
TEXT
content=chapter5
content=chapter5
========================
Expression: /EXAMPLE
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT EXAMPLE
ATTRIBUTE prop1
TEXT
content=gnome is great
content=gnome is great
ATTRIBUTE prop2
TEXT
content=& linux too
content=& linux too