Saxon/C
1.1.2
Saxon Processor library for C/C++/PHP
|
Saxon/C 1.1.2 is the latest release of Saxon-HE/PE/EE on the C/C++ programming platform. The APIs support the specifications XSLT 3.0, XQuery 3.0, Schema Validation 1.0/1.1 and XPath 2.0/3.0 from C/C++ or PHP applications.
Saxon/C is built from the Saxon 9.8.0.15 Java product using the Excelsior JET tool (version 15.3).
Platforms supported: Linux 32/64-bit, Mac OS and Windows 64-bit.
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)
ln -s /usr/lib/Saxonica/Saxon-EDITIONC#.#.#/libsaxonEDITION.so /usr/lib/libsaxonEDITION.so
export LD_LIBRARY_PATH=/usr/lib/rt/lib/i386:$LD_LIBRARY_PATH
ln -s /usr/lib/Saxonica/Saxon-EDITIONC#.#.#/rt /usr/lib/rt
; configuration for php Saxon HE/PE/EE module extension=saxon.so save the file.
php5enmod saxon
gcc -m32 -I$jdkdir/include -I$jdkdir/include/linux -I /System/Library/Frameworks/JavaVM.framework/Headers ../SaxonCGlue.c ../SaxonCProcessor.c ../SaxonCXPath.c testXSLT.c -o testXSLT -ldl -lc $1
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 $1 $2
orprocessor->setConfigurationProperty("xsdversion", "1.1");
processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
Name | Example | Comme |
---|---|---|
'node'=xdmValue | setParameter("node",xdmNodeObj) | Sets the source document for transformation. We also accept the parameter names 'item'. |
param=xdmValue | setParameter("numParam",value1) | set the value of a stylesheet parameter |
Name | Example | Comme |
---|---|---|
![serialization name]=value | setProperty("!INDENT","yes") | Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation |
'o'=filename | setProperty("o", "output.xml") | Sets the destination for the result of the transformation to the specificed filename |
'it'=name | setProperty("it", "name") | Set the initial named template for the transformation by name |
'dtd'=boolean | setProperty("dtd", "true") | Set whether DTD validation should be applied to documents loaded |
'im'=name | setProperty("im", "mode-name") | Set the initial mode for the transformation |
's'=filename | setProperty("s", "filename") | Identifies the source file or directory. Mandatory unless the -it option is used. |
'resources'=directory | setProperty("resources", "dir") | Specifies the directory where the resources file are found |
'extc'=dir/saxonc | setProperty("extc", "dir/saxonc") | Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests |
'm' | setProperty("m", "") | The presence of this property creates a message listener which is available in the C/C++ API of Saxon/C |
SaxonProcessor *processor = new SaxonProcessor(true);
XsltProcessor * xslt = processor->newTransformer();
cout<<"Hello World"<<endl;
cout<<"Test output: "<<xslt->transformFileToString("cat.xml","test.xsl")<<endl;
SaxonProcessor * processor = new SaxonProcessor(false);
XsltProcessor * xslt = processor->newTransformer();
xslt->setSourceFile("xml/foo.xml");
XdmAtomicValue * xdmvaluex =processor->makeStringValue("Hello to you");
if(xdmvaluex !=NULL){
cerr<< "xdmvaluex ok"<<endl;
}
xslt->setParameter("a-param", xdmvaluex);
const char * result = test->transformFileToString(NULL, "xsl/foo.xsl");
if(result != NULL) {
cerr<<result<<endl;
} else {
cerr<<"Result is NULL"<<endl;
}
processor->clearParameters(true);
processor->clearProperties();
Name | Example | Comme |
---|---|---|
'node'=xdmValue | setParameter("node",xdmNodeObj) | Sets the source document for query. We also accept the parameter names 'item'. |
param=xdmValue | setParameter("numParam",value1) | Set the value of external variable defined in the query |
Name | Example | Comme |
---|---|---|
'base'=base-URI | setProperty("base", "/home/username/example") | |
'q'=query-fileName | setProperty("q", "filename") | Identifies the file containing the query. |
'qs'=query-string | setProperty("qs", "saxon:line-number((//person)[1])") | Allows the query to be specified inline. |
![serialization name]=value | setProperty("!INDENT","yes") | Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation |
'o'=filename | setProperty("o", "output.xml") | Sets the destination for the result of the XQuery to the specificed filename |
'dtd'=boolean | setProperty("dtd", "true") | Set whether DTD validation should be applied to documents loaded |
's'=filename | setProperty("s", "filename") | Identifies the source file or directory. Mandatory unless the -it option is used. |
'resources'=directory | setProperty("resources", "dir") | Specifies the directory where the resources file are found |
'sa'=boolean | setProperty("sa", "true") | Invoke a schema-aware query. Requires Saxon-EE to be installed. |
'extc'=dir/saxonc | setProperty("extc", "dir/saxonc") | Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests |
SaxonProcessor *processor = new SaxonProcessor(true);
XsltProcessor * xslt = processor->newXQueryProcessor();
queryProc->setProperty("s", "cat.xml");
queryProc->setProperty("q", "family.xq");
queryProc->runQueryToString();
Name | Example | Comme |
---|---|---|
'node'=xdmValue | setParameter("node",xdmNodeObj) | Sets the source document for query. We also accept the parameter names 'item'. |
param=xdmValue | setParameter("numParam",value1) | Set the value of external variable defined in the query |
Name | Example | Comme |
---|---|---|
![serialization name]=value | setProperty("!INDENT","yes") | Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation |
'o'=filename | setProperty("o", "output.xml") | Sets the destination for the result of the XQuery to the specificed filename |
'dtd'=boolean | setProperty("dtd", "true") | Set whether DTD validation should be applied to documents loaded |
's'=filename | setProperty("s", "filename") | Identifies the source file or directory. Mandatory unless the -it option is used. |
'resources'=directory | setProperty("resources", "dir") | Specifies the directory where the resources file are found |
'extc'=dir/saxonc | setProperty("extc", "dir/saxonc") | Specifies the full path to the C/C++ Saxon/C API library which contains the extension function. See example in samples/cppTests |
SaxonProcessor *processor = new SaxonProcessor();
XPathProcessor * xpath = processor->newXPathProcessor();
xpath->setContextFile("cat.xml");
XdmValue * resultValues = xpath->evaluate("//person");
if(resultValues == NULL) {
printf("result is null \n");
} else {
cout<<"Number of items="<<resultValues->size()<<endl;
for(int i =0; i< resultValues->size();i++){
XdmItem * itemi = resultValues->itemAt(i);
if(itemi == NULL) {
cout<<"Item at position "<<i<<" should not be null"<<endl;
break;
}
cout<<"Item at "<<i<<" ="<<itemi->getStringValue(processor)<<endl;
}
}
xpath->clearParameters(true);
xpath->clearProperties();
Name | Example | Comme |
---|---|---|
'node'=xdmValue | setParameter("node",xdmNodeObj) | Sets the source document for the validation. We also accept the parameter names 'item'. |
param=xdmValue | setParameter("numParam",value1) | Set the value of external variable defined in the query |
Name | Example | Comme |
---|---|---|
![serialization name]=value | setProperty("!INDENT","yes") | Influence the serialization of the XML by the parameters specified with a exclamation mark with a name and the value. See Documentation |
'o'=filename | setProperty("o", "output.xml") | Sets the destination for the result of the XQuery to the specificed filename |
'string'=xml-string | setProperty("string",xml-string) | Sets the source document aas a string for validation. Parsing will happen when the validate method has been called. |
'dtd'=boolean | setProperty("dtd", "true") | Set whether DTD validation should be applied to documents loaded |
's'=filename | setProperty("s", "filename") | Identifies the source file or directory. Mandatory unless the -it option is used. |
'resources'=directory | setProperty("resources", "dir") | Specifies the directory where the resources file are found |
'report-node'=boolean | setProperty("report-node", "true") | Flag for validation reporting feature. Error validation failures are represented in an XML document |
'report-file'=filename | setProperty("report-file", "filename") | Switches on the validation reporting feature. Validation failures collected and saved in an XML format in a file. |
'verbose'=boolean | setProperty("verbose", "true") | Set verbose mode to output to the terminal validation exceptions. The default is on providing the reporting feature has not been enabled. |
'element-type'=string | setProperty("element-type", "{uri}local") | Set the name of the required type of the top-level element of the document to be validated. The string should be in the Clark notation: {uri}local |
'element-name'=string | setProperty("element-name", "{uri}local") | Set the name of the required top-level element of the document to be validated (that is, the name of the outermost element of the document). The string should be in the Clark notation: {uri}local |
'lax'=boolean | setProperty("lax", "true") | The validation mode may be either strict or lax. Default is strict. This property indicates that lax validation is required. |
SaxonProcessor * processor = new SaxonProcessor(true);
processor->setConfigurationProperty("xsdversion", "1.1");
processor->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
SchemaValidator * val = processor->newSchemaValidator();
val->registerSchemaFromFile("family-ext.xsd");
val->registerSchemaFromFile("family.xsd");
val->setProperty("report-node", "true");
val->setProperty("verbose", "true");
val->validate("family.xml");
XdmNode * node = val->getValidationReport();
if(node != NULL) {
cout<<endl<<"Validation Report"<<node->getStringValue()<<endl;
} else {
cout<<endl<<"Error: Validation Report is NULL"<<endl;
}
SaxonProcessor() Default Constructor. Create an unlicensed Saxon Processor | |
SaxonProcessor(boolean $license) 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 | |
SaxonProcessor(boolean $license, string $cwd) 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 | |
XdmValue | createAtomicValue($primitive_type val) Create an Xdm Atomic value from any of the main primitive types (i.e. bool, int, float, double, string) |
Saxon\XdmNode | parseXmlFromString(string $value) Create an XdmNode object. The $value is a lexical representation of the XML document |
Saxon\XdmNode | parseXmlFromFile(string $fileName) 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. |
void | setcwd(string $cwd) Set the current working directory used to resolve against files |
Saxon\XdmNode | parseXmlFromFile(string $fileName) 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. |
void | setResourceDirectory(string $dir) Set the resources directory of where Saxon can locate data folder |
void | setConfigurationProperty(string $name, string $value) Set a configuration property specific to the processor in use. Properties specified here are common across all the processors. See Configuration Features |
Saxon\XsltProcessor | newXsltProcessor() Create an XsltProcessor in the PHP environment. An XsltProcessor is used to compile and execute XSLT sytlesheets |
Saxon\XQueryProcessor | newXQueryProcessor() Create an XQueryProcessor in the PHP environment. An XQueryProcessor is used to compile and execute XQuery queries |
Saxon\XPathProcesssor | newXPathProcessor() Create an XPathProcessor in the PHP environment. An XPathProcessor is used to compile and execute XPath expressions |
Saxon\SchemaValidator | newSchemaValidator() Create a SchemaValidator in the PHP environment. A SchemaValidator provides capabilities to load and cache XML schema definitions. You can also valdiate source documents with egistered XML schema definitions |
string | version() Report the Java Saxon version |
void | registerPHPFunctions(string $library) Enables the ability to use PHP functions as XSLT functions. Accepts as parameter the full path of the Saxon/C PHP Extension library. This is needed to do the callbacks |
void | transformFileToFile(string $sourceFileName, string $stylesheetFileName, string outputfileName) Perform a one shot transformation. The result is stored in the supplied outputfile name. |
string | transformFileToString(string $sourceFileName, string $stylesheetFileName) Perform a one shot transformation. The result is returned as a string. If there are failures then a null is returned |
XdmValue | transformFileToValue(string $fileName) Perform a one shot transformation. The result is returned as an XdmValue |
void | transformToFile() Perform the transformation based upon cached stylesheet and source document. |
string | transformToString() |
XdmValue | transformToValue() Perform the transformation based upon cached stylesheet and any source document. Result returned as an XdmValue object. If there are failures then a null is returned |
void | compileFromFile(string $fileName) Compile a stylesheet suplied as by file name |
void | compileFromString(string $str) Compile a stylesheet received as a string. |
void | compileFromFileAndSave(string $xslFileName, string $sefFileName) compile a stylesheet received as a file and save to an exported file (SEF). (Saxon-EE/C required). |
void | compileFromStringAndSave(string $str, string $sefFileName) compile a stylesheet received as a string and save to an exported file (SEF). (Saxon-EE/C required). |
void | compileFromValue(XdmNode $node) Compile a stylesheet received as an XdmNode. |
void | setOutputFile(string $fileName) Set the output file name of where the transformation result is sent |
void | setSourceFromXdmValue(XdmValue $value) The source used for a query or stylesheet. Requires an XdmValue object |
void | setSourceFromFile(string $filename) The source used for query or stylesheet. Requires a file name as string |
void | setParameter(string $name, XdmValue $value) Set the parameters required for XSLT stylesheet |
void | setProperty(string $name, string $value) Set properties for the stylesheet. |
void | clearParameters() Clear parameter values set |
void | clearProperties() Clear property values set |
void | exceptionClear() Clear any exception thrown |
string | getErrorCode(int $i) Get the ith error code if there are any errors |
string | getErrorMessage(int $i) Get the ith error message if there are any error |
int | getExceptionCount() Get number of error during execution or evaluate of stylesheet |
XdmValue | runQueryToValue() compile and evaluate the query. Result returned as an XdmValue object. If there are failures then a null is returned |
string | runQueryToString() compile and evaluate the query. Result returned as string. If there are failures then a null is returned |
void | runQueryToFile(string $outfilename) compile and evaluate the query. Save the result to file |
void | setQueryContent(string $str) query supplied as a string |
void | setQueryItem(XdmItem $item) ** |
void | setQueryFile($string $filename) query supplied as a file |
void | setContextItemFromFile(string $fileName) Set the initial context item for the query. Supplied as filename |
void | setContextItem(Xdm $obj) Set the initial context item for the query. Any one of the objects are accepted: XdmValue, XdmItem, XdmNode and XdmAtomicValue. |
void | setQueryBaseURI(string $uri) Set the static base URI for a query expressions compiled using this XQuery Processor. The base URI is part of the static context, and is used to resolve any relative URIS appearing within a query |
void | declareNamespace(string $prefix, string $namespace) Declare a namespace binding as part of the static context for XPath expressions compiled using this XQuery processor |
void | setParameter(string $name, XdmValue $value) Set the parameters required for XQuery Processor |
void | setProperty(string $name, string $value) Set properties for Query. |
void | clearParameters() Clear parameter values set |
void | clearProperties() Clear property values set |
void | exceptionClear() Clear any exception thrown |
string | getErrorCode(int $i) Get the ith error code if there are any errors |
string | getErrorMessage(int $i) Get the ith error message if there are any error |
int | getExceptionCount() Get number of error during execution or evaluate of query |
void | setContextItem(string $fileName) Set the context item from a XdmItem |
void | setContextFile(string $fileName) Set the context item from file |
boolean | effectiveBooleanValue(string $xpathStr) Evaluate the XPath expression, returning the effective boolean value of the result. |
XdmValue | evaluate(string $xpathStr) Compile and evaluate an XPath expression, supplied as a character string. Result is an XdmValue |
XdmItem | evaluateSingle(string $xpathStr) Compile and evaluate an XPath expression whose result is expected to be a single item, with a given context item. The expression is supplied as a character string. |
void | declareNamespace(string $prefix, string $namespace) Declare a namespace binding as part of the static context for XPath expressions compiled using this XPathProcessor |
void | setBaseURI(string $uri) Set the static base URI for XPath expressions compiled using this XQuery Processor. The base URI is part of the static context, and is used to resolve any relative URIS appearing within a query |
void | setParameter(string $name, XdmValue $value) Set the parameters required for XQuery Processor |
void | setProperty(string $name, string $value) Set properties for Query. |
void | clearParameters() Clear parameter values set |
void | clearProperties() Clear property values set |
void | exceptionClear() Clear any exception thrown |
string | getErrorCode(int $i) Get the ith error code if there are any errors |
string | getErrorMessage(int $i) Get the ith error message if there are any error |
int | getExceptionCount() Get number of error during execution or evaluate of stylesheet and query, respectively |
void | setSourceNode(XdmNode $node) The instance document to be validated. Supplied as an Xdm Node |
void | setOutputFile(string $fileName) The instance document to be validated. Supplied file name is resolved and accessed |
void | registerSchemaFromFile(string $fileName) Register the Schema which is given as file name. |
void | registerSchemaFromString(string $schemaStr) Register the Schema which is given as a string representation. |
void | validate() Validate an instance document supplied as a Source object. Assume source document has already been supplied through accessor methods |
void | validate(string $fileName) Validate an instance document supplied as a Source object. $filename - The name of the file to be validated. $filename can be null |
XdmNode | validateToNode() 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 |
XdmNode | validateToNode(string $fileName) 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 |
XdmNode | getValidationReport Get the valdiation report produced after valdiating the soucre document. The reporting feature is switched on via setting the property on the SchemaValidator: validator.setProperty('report', 'true'). Return XdmNode |
void | setParameter(string $name, XdmValue $value) Set the parameters required for XQuery Processor |
void | setProperty(string $name, string $value) Set properties for Schema Validator. |
void | clearParameters() Clear parameter values set |
void | clearProperties() Clear property values set |
void | exceptionClear() Clear any exception thrown |
string | getErrorCode(int $i) Get the ith error code if there are any errors |
string | getErrorMessage(int $i) Get the ith error message if there are any error |
int | getExceptionCount() Get number of error during execution of the validator |
string | getStringValue() Get the string value of the item. For a node, this gets the string value of the node. For an atomic value, it has the same effect as casting the value to a string. In all cases the result is the same as applying the XPath string() function. |
boolean | isNode() Determine whether the item is a node value or not. |
boolean | isAtomic() Determine whether the item is an atomic value or not. |
XdmAtomicValue | getAtomicValue() Provided the item is an atomic value we return the XdmAtomicValue otherwise return null |
XdmNode | getNodeValue() Provided the item is a node value we return the XdmNode otherwise return null |
string | getStringValue() Get the string value of the item. For a node, this gets the string value of the node. |
int | getNodeKind() Get the kind of node |
string | getNodeName et the name of the node, as a EQName |
boolean | isAtomic() Determine whether the item is an atomic value or a node. This method will return FALSE as the item is not atomic |
int | getChildCount() Get the count of child node at this current node |
int | getAttributeCount() Get the count of attribute nodes at this node |
XdmNode | getChildNode(int index) Get the n'th child node at this node. If the child node selected does not exist then return null |
XdmNode | getParent() Get the parent of this node. If parent node does not exist then return null |
XdmNode | getAttributeNode(int $index) Get the n'th attribute node at this node. If the attribute node selected does not exist then return null |
string | getAttributeValue(int $index) Get the n'th attribute node value at this node. If the attribute node selected does not exist then return null |
string | getStringValue Get the string value of the item. For an atomic value, it has the same effect as casting the value to a string. In all cases the result is the same as applying the XPath string() function. |
boolean | getBooleanValue Get the value converted to a boolean using the XPath casting rules |
double | getDoubleValue Get the value converted to a double using the XPath casting rules. If the value is a string, the XSD 1.1 rules are used, which means that the string "+INF" is recognised |
long | getLongValue Get the value converted to an integer using the XPath casting rules |
boolean | isAtomic Determine whether the item is an atomic value or a node. Return TRUE if the item is an atomic value |
<?php
$xmlfile = "xml/foo.xml";
$xslFile = "xsl/foo.xsl";
$proc = new Saxon\SaxonProcessor();
$version = $proc->version();
echo 'Saxon Processor version: '.$version;
$xsltProc = $saxonProc->newXsltProcessor();
$xsltProc->setSourceFromFile($xmlfile);
$xsltProc->compileFromFile($xslFile);
$result = $xsltProc->transformToString();
if($result != null) {
echo 'exampleSimple1:
';
echo 'Output:'.$result;
} else {
echo "Result is null";
}
$xsltProc->clearParameters();
$xsltProc->clearProperties();
?>
<?php
$xmlfile = "xml/foo.xml";
$xslFile = "xsl/foo.xsl";
$proc = new Saxon\SaxonProcessor();
$xsltProc = $saxonProc->newXsltProcessor();
$xsltProc->setSourceFromFile($xmlFile);
$xsltProc->compileFromFile($xslFile);
$result = $xsltProc->transformToString();
if($result == NULL) {
$errCount = $xsltProc->getExceptionCount();
if($errCount > 0 ){
for($i = 0; $i < $errCount; $i++) {
$errCode = $xsltProc->getErrorCode(intval($i));
$errMessage = $xsltProc->getErrorMessage(intval($i));
echo 'Expected error: Code='.$errCode.' Message='.$errMessage;
}
$xsltProc->exceptionClear();
}
}
echo $result;
$xsltProc->clearParameters();
$xsltProc->clearProperties();
?>