Project

Profile

Help

Revision 7e915d07

Added by O'Neil Delpratt almost 6 years ago

Saxon/C bug fixes and documentation fixes: #2640

View differences:

latest9.6/hec/Saxon.C.API/XdmValue.cpp
19 19
		values.push_back(value);
20 20
		xdmSize++; 
21 21
		jValues = NULL;
22
        valueType = NULL
22
        valueType = NULL;
23 23
	}
24 24

  
25 25

  
latest9.6/hec/Saxon.C.API/XdmValue.h
40 40
	XdmValue(){
41 41
		xdmSize = 0;
42 42
		refCount = 1;
43
		jValues = NULL;		
43
		jValues = NULL;
44
		valueType = NULL;
44 45
	}
45 46

  
46 47
	XdmValue(SaxonProcessor * p){
47 48
		proc = p;
48 49
		jValues = NULL;
49 50
		refCount = 1;
51
		valueType = NULL;
50 52
	}
51 53

  
52 54

  
latest9.6/hec/Saxon.C.API/php_saxon.cpp
3304 3304
    php_info_print_table_start();
3305 3305
    php_info_print_table_header(2, "Saxon/C", "enabled");
3306 3306
    php_info_print_table_row(2, "Saxon/C EXT version", "1.0.0");
3307
    php_info_print_table_row(2, "Saxon-HEJ", "9.6.0.8");
3307
    php_info_print_table_row(2, "Saxon", "9.6.0.9");
3308 3308
    php_info_print_table_row(2, "Excelsior JET", "11 MP1");
3309 3309
    php_info_print_table_end();
3310 3310
    DISPLAY_INI_ENTRIES();
latest9.6/hec/Saxon.C.API/readme.md
9 9

  
10 10
Saxon/C 1.0.0 is the latest major release of Saxon-HE/PE/EE on the C/C++ programming platform. The APIs support the specifications XSLT 2.0/3.0, XQuery 1.0/3.0, Schema Validation 1.0/1.1 and XPath 2.0/3.0 from C/C++ or PHP applications.
11 11

  
12
Platforms supported: Linux Only. 
12
Saxon/C is built from the Saxon 9.6.0.9 Java product using the Excelsior JET tool (version 11 MP1).
13

  
14
Platforms supported: Linux Only.
13 15
Windows will be supported shortly
14 16

  
15
Saxon/C is release in three separate editions which replicating the products on the Java platform: Enterprise (Saxon/EEC), Professional Editon (Saxon-PE/C), and Home Edition (Saxon-HE/C)
17
Saxon/C is release in three separate editions which replicating the products on the Java platform: Enterprise (Saxon-EE/C), Professional Editon (Saxon-PE/C), and Home Edition (Saxon-HE/C)
16 18

  
17 19
<div id='installation'/>
18 20
## Installation: ##
......
20 22
#### Saxon-HE/C, Saxon-PE/C and Saxon-EE/C: ####
21 23
To install any of the Saxon/C releases, unzip the the file libsaxon-EDITION-setup-v1.0.0.zip and execute the command './libsaxon-EDITION-setup-v1.0.0'
22 24
First step is to select the destination of where the product files will be installed.
23
The product files are unpacked in the directory 'Saxon-HEC'
25
The product files are unpacked in the directory 'Saxon-EDITIONC'
26

  
27
Link the dynamic saxon library so it can be found. For example:
28

  
29
	ln -s /usr/lib/Saxonica/Saxon-EDITIONC1.0.0/libsaxonEDITION.so /usr/lib/libsaxonEDITION.so
24 30

  
25 31
You need to setup the environment for the jet jvm. The jvm is in the directory JET-home=Saxonica/Saxon-EDITION1.1.0/rt
26 32
The directory JET-home/lib/i386  or JET_home/lib/amd64 (for 64-bit machines) must be listed in the LD_LIBRARY_PATH environment variable. For instance, if you
......
29 35
    export LD_LIBRARY_PATH=/usr/lib/rt/lib/i386:$LD_LIBRARY_PATH
30 36

  
31 37
We assume that the 'rt' directory is in the location /usr/lib.
32
The Saxon-EDITION API assumes the library is installed as follows: '/usr/lib/libsaxonhec.so', '/usr/lib/libsaxonpec.so'or '/usr/lib/libsaxoneec.so'
33
The directory 'saxon-data' must be copied to '/usr/lib'
38

  
39
Link the jetvm library so it can be found. For example:
40

  
41
	ln -s /usr/lib/Saxonica/Saxon-EDITIONC1.0.0/rt /usr/lib/rt
42

  
43
The Saxon-EDITION API assumes the library is installed as follows: '/usr/lib/libsaxonhec.so', '/usr/lib/libsaxonpec.so' or '/usr/lib/libsaxoneec.so'
44
The directory 'saxon-data' must be linked ot copied to '/usr/lib', alternatively you can use the ennvironment variable SAXONC_HOME to locate directory.
34 45

  
35 46

  
36 47
#### PHP extension: ####
......
43 54
* make
44 55
* sudo make install
45 56

  
46
Update the php.ini file (if using ubuntu it is usually in the location '/etc/php5/apache2/') to contain the php extension: insert the following in the Dynamic Extensions section: extension=saxon.so
57
Create a module conf file:
58

  
59
nano /etc/php5/mods-available/saxon.ini
60
and add contents:
61

  
62
	; configuration for php Saxon HE/PE/EE module
63
	    extension=saxon.so
64
	save the file.
65

  
66
Enable the module for PHP:
67

  
68
	php5enmod saxon
69

  
70
Alternatively, you can update the php.ini file (if using ubuntu it is usually in the location '/etc/php5/apache2/') to contain the php extension: insert the following in the Dynamic Extensions section: extension=saxon.so
47 71

  
48 72
* sudo service apache2 restart
49 73

  
......
77 101

  
78 102
The following files are required to build Saxon/C on C++:  SaxonCGlue.c, SaxonCXPath.c, XdmValue.cpp, XdmItem.cpp, XdmNode.cpp, XdmAtomicValue.cpp, SaxonProcessor.cpp, XsltProcessor.cpp and XQueryProcessor.cpp, XPathProcessor.cpp, SchemaValidator.cpp
79 103

  
80
To compile the sample test code in C++ execute the 'build.sh' file the directory 'cppTests'. This file builds executables for the test cases testing XSLT, XPath, XQuery and schema Validator. The command is similar to the following: 
104
To compile the sample test code in C++ execute the 'build.sh' file the directory 'cppTests'. This file builds executables for the test cases testing XSLT, XPath, XQuery and schema Validator. The command is similar to the following:
81 105

  
82 106
> g++ -m32  ../bin/SaxonCGlue.o ../bin/SaxonCXPath.o ../bin/SaxonProcessor.o ../bin/XQueryProcessor.o ../bin/XsltProcessor.o ../bin/XPathProcessor.o ../bin/XdmValue.o ../bin/XdmItem.o ../bin/XdmNode.o ../bin/XdmAtomicValue.o ../bin/SchemaValidator.o testXSLT.cpp -o testXSLT -ldl -lc -lsaxon $1 $2
83 107

  
......
90 114

  
91 115
The example below shows how we can set the configuration features on the processor before we create any of the processors (.e.g. XsltProcessor, XQueryProcess, etc):
92 116

  
93
> processor->setConfigurationProperty("xsdversion", "1.1"); 
117
> processor->setConfigurationProperty("xsdversion", "1.1");
94 118
or
95 119
> processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
96 120

  
......
125 149

  
126 150

  
127 151
Example 1:
128
 
152

  
129 153
<pre><code>
130 154
	SaxonProcessor *processor = new SaxonProcessor(true);
131 155
	XsltProcessor * xslt = processor->newTransformer();
......
142 166
        xslt->setSourceFile("xml/foo.xml");
143 167
	XdmAtomicValue * xdmvaluex =processor->makeStringValue("Hello to you");
144 168
	if(xdmvaluex !=NULL){
145
		cerr<< "xdmvaluex ok"<<endl; 			
169
		cerr<< "xdmvaluex ok"<<endl;
146 170
	}
147 171
	xslt->setParameter("a-param", xdmvaluex);
148 172
        const char * result = test->transformFileToString(NULL, "xsl/foo.xsl");
......
214 238
<pre><code>
215 239
	SaxonProcessor *processor = new SaxonProcessor();
216 240
	XPathProcessor * xpath = processor->newXPathProcessor();
217
 
241

  
218 242
	xpath->setContextFile("cat.xml");
219 243

  
220 244
	XdmValue * resultValues = xpath->evaluate("//person");
221
	
245

  
222 246
	if(resultValues == NULL) {
223 247
		 printf("result is null \n");
224 248
	} else {
......
229 253
				cout<<"Item at position "<<i<<" should not be null"<<endl;
230 254
				break;
231 255
			}
232
			cout<<"Item at "<<i<<" ="<<itemi->getStringValue(processor)<<endl;		
256
			cout<<"Item at "<<i<<" ="<<itemi->getStringValue(processor)<<endl;
233 257
		}
234 258
	}
235 259
	xpath->clearParameters(true);
......
262 286
	processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
263 287
	SchemaValidator * val = processor->newSchemaValidator();
264 288
	val->registerSchemaFromFile("family-ext.xsd");
265
      
289

  
266 290
	val->registerSchemaFromFile("family.xsd");
267
	val->setProperty("report-node", "true");	
291
	val->setProperty("report-node", "true");
268 292
	val->setProperty("verbose", "true");
269 293
	val->validate("family.xml");
270
	XdmNode * node = val->getValidationReport(); 
294
	XdmNode * node = val->getValidationReport();
271 295
	if(node != NULL) {
272 296
		cout<<endl<<"Validation Report"<<node->getStringValue()<<endl;
273 297
	} else {
......
294 318
|     | *SaxonProcessor()* <br> *Default Constructor. Create an unlicensed Saxon Processor*   |
295 319
|   | SaxonProcessor(boolean $license)<br> *Constructor. Indicates whether the Processor requires features of Saxon that need a license file. If false, the method will creates a Configuration appropriate for Saxon HE (Home edition). If true, the method will create a Configuration appropriate to the version of the software that is running  Saxon-PE or Saxon-EE*  |
296 320
|  |SaxonProcessor(boolean $license, string $cwd) <br> *Constructor. Indicates whether the Processor requires features of Saxon that need a license file. The cwd arugment is used to manually set the current working directory used for executions of source files*  |
321
| XdmValue | createAtomicValue($primitive_type val)<br> *Create an Xdm Atomic value from any of the main primitive types (i.e. bool, int, float, double, string)* |
297 322
| Saxon\\XdmNode | parseXmlFromString(string $value) <br> *Create an XdmNode object. The $value is a lexical representation of the XML document* |
298 323
| Saxon\\XdmNode | parseXmlFromFile(string $fileName) <br> *Create an XdmNode object. Value is a string type and the file name to the XML document. File name can be relative or absolute. IF relative the cwd is used to resolve the file.* |
299 324
| void | setcwd(string $cwd) <br> *Set the current working directory used to resolve against files* |
......
375 400
| void | setProperty(string $name, string $value) <br> *Set properties for Query.* |
376 401
| void | clearParameters() <br> *Clear parameter values set* |
377 402
| void | clearProperties() <br> *Clear property values set* |
378
| void | exceptionClear() <br> *Clear any exception thrown* 
403
| void | exceptionClear() <br> *Clear any exception thrown*
379 404
| string | getErrorCode(int $i) <br> *Get the ith error code if there are any errors*  |
380 405
| string | getErrorMessage(int $i) <br> *Get the ith error message if there are any error* |
381
| int | getExceptionCount() <br> *Get number of error during execution or evaluate of stylesheet and query, respectively* | 
406
| int | getExceptionCount() <br> *Get number of error during execution or evaluate of stylesheet and query, respectively* |
382 407

  
383 408
#### Saxon\\SchemaValidator class ####
384 409
<sup>PHP API</sup>
......
389 414
| void | setOutputFile(string $fileName) <br> *The instance document to be validated. Supplied file name is resolved and accessed* |
390 415
| void | registerSchemaFromFile(string $fileName) <br> *Register the Schema which is given as file name.* |
391 416
| void | registerSchemaFromString(string $schemaStr) <br> *Register the Schema which is given as a string representation.* |
392
| void | validate() <br> *Validate an instance document supplied as a Source object. Assume source document has already been supplied through accessor methods* | 
417
| void | validate() <br> *Validate an instance document supplied as a Source object. Assume source document has already been supplied through accessor methods* |
393 418
| void | validate(string $fileName) <br> *Validate an instance document supplied as a Source object. $filename - The name of the file to be validated. $filename can be null* |
394 419
| XdmNode | validateToNode() <br> *Validate an instance document supplied as a Source object with the validated document returned to the calling program. Assume source document has already been supplied through accessor methods* |
395 420
| XdmNode | validateToNode(string $fileName) <br> *Validate an instance document supplied as a Source object with the validated document returned to the calling program. $filename - The name of the file to be validated. $filename can be null* |
......
398 423
| void | setProperty(string $name, string $value) <br> *Set properties for Schema Validator.* |
399 424
| void | clearParameters() <br> *Clear parameter values set* |
400 425
| void | clearProperties() <br> *Clear property values set* |
401
| void | exceptionClear() <br> *Clear any exception thrown* 
426
| void | exceptionClear() <br> *Clear any exception thrown*
402 427
| string | getErrorCode(int $i) <br> *Get the ith error code if there are any errors*  |
403 428
| string | getErrorMessage(int $i) <br> *Get the ith error message if there are any error* |
404 429
| int | getExceptionCount() <br> *Get number of error during execution of the validator* |
......
456 481

  
457 482
Example code XSLT processing:
458 483
<pre><code>
459
	<?php 
484
	<?php
460 485
	        $xmlfile = "xml/foo.xml";
461 486
	        $xslFile = "xsl/foo.xsl";
462
		$proc = new SaxonProcessor();
487
		$proc = new Saxon\\SaxonProcessor();
463 488
            	$version = $proc->version();
464 489
            	echo 'Saxon Processor version: '.$version;
465
                $proc->setSourceFile($xmlfile);
466
                $proc->setStylesheetFile($xslFile);      
467
                $result = $proc->transformToString();               
468
		if($result != null) {               
490
		$xsltProc = $saxonProc->newXsltProcessor();
491
                $xsltProc->setSourceFromFile($xmlfile);
492
                $xsltProc->compileFromFile($xslFile);
493
                $result = $xsltProc->transformToString();
494
		if($result != null) {
469 495
		  echo '<b>exampleSimple1:</b><br/>';
470 496
		  echo 'Output:'.$result;
471 497
		} else {
472 498
			echo "Result is null";
473 499
		}
474
		$proc->clearParameters();
475
		$proc->clearProperties(); 
500
		$xsltProc->clearParameters();
501
		$xsltProc->clearProperties();
476 502
	?>
477 503
</code></pre>
478 504

  
......
480 506
In the example below we show how to debug if something unexpected is happening. It is also very useful to examine the apache error.log file:
481 507

  
482 508
<pre><code>
483
	<?php 
509
	<?php
484 510
	        $xmlfile = "xml/foo.xml";
485 511
	        $xslFile = "xsl/foo.xsl";
486
		$proc = new SaxonProcessor();
487
                $proc->setSourceFile($xmlFile);
488
                $proc->setStylesheetFile($xslFile);
489
                
490
                $result = $proc->transformToString();
491
                
512
		$proc = new Saxon\\SaxonProcessor();
513
		$xsltProc = $saxonProc->newXsltProcessor();
514
                $xsltProc->setSourceFromFile($xmlFile);
515
                $xsltProc->compileFromFile($xslFile);
516

  
517
                $result = $xsltProc->transformToString();
518

  
492 519
                if($result == NULL) {
493
                    $errCount = $proc->getExceptionCount();
494
				    if($errCount > 0 ){ 
520
                    $errCount = $xsltProc->getExceptionCount();
521
				    if($errCount > 0 ){
495 522
				        for($i = 0; $i < $errCount; $i++) {
496
					       $errCode = $proc->getErrorCode(intval($i));
497
					       $errMessage = $proc->getErrorMessage(intval($i));
523
					       $errCode = $xsltProc->getErrorCode(intval($i));
524
					       $errMessage = $xsltProc->getErrorMessage(intval($i));
498 525
					       echo 'Expected error: Code='.$errCode.' Message='.$errMessage;
499 526
					   }
500
						$proc->exceptionClear();	
527
						$xsltProc->exceptionClear();
501 528
					}
502
                
503
                
504
                }                
529

  
530

  
531
                }
505 532
                echo $result;
506
            	$proc->clearParameters();
507
		$proc->clearProperties();
533
            	$xsltProc->clearParameters();
534
		$xsltProc->clearProperties();
508 535
	?>
509 536
</code></pre>
510 537

  
......
523 550
<div id='limitations'/>
524 551
## Limitations: ##
525 552

  
526
The following limitations apply to the the 1.1.0 release:
553
The following limitations apply to the the 1.0.0 release:
527 554

  
528 555
* No support for the XdmFunction type in the Xdm data model
529
* No supports for XSLT and XQuery extension functions
556
* No supports for external functions in XSLT and XQuery
530 557

  
531 558
### Feedback/Comments: ###
532 559

  
533 560
Please use the help forums and bug trackers at [saxonica.plan.io](https://saxonica.plan.io/projects/saxon-c) if you need help or advice.
534 561

  
535 562

  
536

  
537
|  | Comment |
latest9.6/hec/samples/cppTests/testXQuery.cpp
37 37
	queryProc->checkException();
38 38
	
39 39
    }
40
	queryProc->setcwd("/home/ond1/work/svn/Saxon.C.Api/cppTests");
40
	queryProc->setcwd(".");
41 41
     queryProc->executeQueryToFile(NULL, "catOutput.xml", NULL);
42 42

  
43 43
		if (exists("catOutput.xml")) {
......
55 55
   queryProc->setProperty("s", "cat.xml");
56 56

  
57 57
    queryProc->setProperty("qs", "<out>{count(/out/person)}</out>");
58
queryProc->setcwd("");
58
queryProc->setcwd(".");
59 59
     queryProc->executeQueryToFile(NULL, "catOutput.xml", NULL);
60 60

  
61 61
		if (queryProc->exceptionOccurred()) {
......
86 86
	if(message != NULL) {
87 87
		cout<<"Error Message="<<message<<" Line number= "<<processor->getException()->getLineNumber(0)<<endl;
88 88
	} else {
89
		cout<<"Error Message - NULL -checkXXX"<<endl;
89
		cout<<"Error Message - NULL check"<<endl;
90 90
	}
91 91
	
92 92
    }
latest9.6/hec/samples/cppTests/testXSLT.cpp
360 360

  
361 361
void exampleSimple1(XsltProcessor  *proc){
362 362
		cout<<"ExampleSimple1 taken from PHP:"<<endl;
363
                proc->setSourceFromFile("../../archive/samples/trax/xml/foo.xml");
364
                proc->compileFromFile("../../archive/samples/trax/xsl/foo.xsl");
363
                proc->setSourceFromFile("../php/trax/xml/foo.xml");
364
                proc->compileFromFile("../php/trax/xsl/foo.xsl");
365 365
  	              
366 366
                const char *result = proc->transformToString();               
367 367
		if(result != NULL) {               
......
387 387

  
388 388
  void exampleSimple2(XsltProcessor  *proc){
389 389
		cout<<"<b>exampleSimple2:</b><br/>"<<endl;
390
                proc->setSourceFromFile("../../archive/samples/trax/xml/foo.xml");
391
                proc->compileFromFile("../../archive/samples/trax/xsl/foo.xsl");
392
                const char * filename = "/home/ond1/temp/output1.xml";
390
                proc->setSourceFromFile("../php/trax/xml/foo.xml");
391
                proc->compileFromFile("../php/trax/xsl/foo.xsl");
392
                const char * filename = "output1.xml";
393 393
		proc->setOutputFile(filename);
394 394
                proc->transformToFile();
395 395
				

Also available in: Unified diff