Altova RaptorXML Server 2025

Das VBScript-Beispiel ist in die folgenden Abschnitte gegliedert:

 

Einrichten und Initialisieren des RaptorXML .NET-Objekts

Validieren einer XML-Datei

Durchführung einer XSLT-Transformation, Rückgabe des Ergebnisses als String

Verarbeiten eines XQuery-Dokuments, Speichern des Ergebnisses in einer Datei

Einrichten der Ausführungssequenz des Skripts und seines Eintrittspunkts

 

Option Explicit On

Imports Altova.RaptorXMLServer

 

Module RaptorXMLRunner

 

  ' The RaptorXML .NET object

    Dim objRaptor As Server

 

  ' Initialize the RaptorXML .NET object

    Sub Init()

 

     ' Allocate a RaptorXML object

       objRaptor = New Server()

 

     ' 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

 

  ' Validate one file

    Sub ValidateXML()

 

     ' Get a validator instance from the RaptorXML object

       Dim objXMLValidator As XMLValidator

       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

          Console.WriteLine("Input string is valid")

       Else

          Console.WriteLine(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 As XSLT

       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

       Console.WriteLine(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 As XQuery

       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

       objXQ.Execute( "MyQueryResult.xml" )

    End Sub

 

    Sub Main()

     ' Entry point; perform all sample functions

       Init()

       ValidateXML()

       RunXSLT()

       RunXQuery()

    End Sub

 

End Module

 

© 2018-2024 Altova GmbH