COM Example: VBScript
The VBScript example below is structured into the following parts:
•Set up and initialize the RaptorXML COM object
•Perform an XSLT transformation, return the result as a string
•Process an XQuery document, save the result in a file
•Set up the execution sequence of the script and its entry point
dim objRaptor
' Initialize the RaptorXML COM object
sub Init
objRaptor = Null
On Error Resume Next
' Try to load the 32-bit COM object; do not throw exceptions if object is not found
Set objRaptor = WScript.GetObject( "", "RaptorXML.Server" )
On Error Goto 0
if ( IsNull( objRaptor ) ) then
' Try to load the 64-bit object (exception will be thrown if not found)
Set objRaptor = WScript.GetObject( "", "RaptorXML_x64.Server" )
end if
' Configure the server: error reporting, HTTP server name and port (IPv6 localhost in this example)
objRaptor.ErrorLimit = 1
objRaptor.ReportOptionalWarnings = true
objRaptor.ServerName = "::1"
objRaptor.ServerPort = 8087
end sub
sub ValidateXML
' Get a validator instance from the Server object
dim objXMLValidator
Set objXMLValidator = objRaptor.GetXMLValidator()
' Configure input data
objXMLValidator.InputFileName = "MyXMLFile.xml"
' Validate; in case of invalid file report the problem returned by RaptorXML
if ( objXMLValidator.IsValid() ) then
MsgBox( "Input string is valid" )
else
MsgBox( objXMLValidator.LastErrorMessage )
end if
end sub
' Perform a transformation; return the result as a string
sub RunXSLT
' Get an XSLT engine instance from the Server object
dim objXSLT
set objXSLT = objRaptor.GetXSLT
' Configure input data
objXSLT.InputXMLFileName = "MyXMLFile.xml"
objXSLT.XSLFileName = "MyTransformation.xsl"
' Run the transformation; in case of success the result will be returned, in case of errors the engine returns an error listing
MsgBox( objXSLT.ExecuteAndGetResultAsString() )
end sub
' Execute an XQuery; save the result in a file
sub RunXQuery
' Get an XQuery engine instance from the Server object
dim objXQ
set objXQ = objRaptor.GetXQuery()
' Configure input data
objXQ.InputXMLFileName = "MyXMLFile.xml"
objXQ.XQueryFileName = "MyQuery.xq"
' Configure serialization (optional - for fine-tuning the result's formatting)
objXQ.OutputEncoding = "UTF8"
objXQ.OutputIndent = true
objXQ.OutputMethod = "xml"
objXQ.OutputOmitXMLDeclaration = false
' Run the query; the result will be serialized to the given path
call objXQ.Execute( "MyQueryResult.xml" )
end sub
' Perform all sample functions
sub main
Init
ValidateXML
RunXSLT
RunXQuery
end sub
' Script entry point; run the main function
main