Altova RaptorXML+XBRL Server 2024

Im nachstehenden Java-Codefragment wird gezeigt, wie grundlegende Funktionalitäten aufgerufen werden können. Der Abschnitt ist in die folgenden Unterabschnitte gegliedert:

 

Navigation zum Ordner "examples" und Erstellen einer RaptorXML COM-Objektinstanz

Validieren einer XML-Datei

Durchführen einer XSLT-Transformation und Rückgabe des Ergebnisses als String

Verarbeiten eines XQuery-Dokuments, Rückgabe des Ergebnisses als String

Ausführen des Projekts

 

Diese Grundfunktionalität ist in den Dateien im RaptorXML+XBRL Server-Applikationsordner im Ordner examples/API enthalten.

 

 

public class RunRaptorXML

{

   // Locate samples installed with the product

   // (will be two levels higher from examples/API/Java)

   // REMARK: You might need to modify this path

      static final String strExamplesFolder = System.getProperty("user.dir") + "/../../" ;

 

      static com.altova.raptorxml.RaptorXMLFactory rxml;

 

 

      static void ValidateXML() throws com.altova.raptorxml.RaptorXMLException

      {

          com.altova.raptorxml.XMLValidator xmlValidator = rxml.getXMLValidator();

          System.out.println("RaptorXML Java - XML validation");

          xmlValidator.setInputFromText( "<!DOCTYPE root [ <!ELEMENT root (#PCDATA)> ]> <root>simple input document</root>" );

             if( xmlValidator.isWellFormed() )

                 System.out.println( "The input string is well-formed" );

             else

                 System.out.println( "Input string is not well-formed: " + xmlValidator.getLastErrorMessage() );

 

             if( xmlValidator.isValid() )

                 System.out.println( "The input string is valid" );

             else

                 System.out.println( "Input string is not valid: " + xmlValidator.getLastErrorMessage() );

      }

 

 

      static void RunXSLT() throws com.altova.raptorxml.RaptorXMLException

      {

          System.out.println("RaptorXML Java - XSL Transformation");

          com.altova.raptorxml.XSLT xsltEngine = rxml.getXSLT();

          xsltEngine.setInputXMLFileName( strExamplesFolder + "simple.xml" );

          xsltEngine.setXSLFileName( strExamplesFolder + "transform.xsl" );

          String result = xsltEngine.executeAndGetResultAsString();

          if( result == null )

              System.out.println( "Transformation failed: " + xsltEngine.getLastErrorMessage() );

          else

              System.out.println( "Result is " + result );

      }

 

 

      static void RunXQuery() throws com.altova.raptorxml.RaptorXMLException

      {

          System.out.println("RaptorXML Java - XQuery execution");

          com.altova.raptorxml.XQuery xqEngine = rxml.getXQuery();

          xqEngine.setInputXMLFileName( strExamplesFolder + "simple.xml" );

          xqEngine.setXQueryFileName( strExamplesFolder + "CopyInput.xq" );

          System result = xqEngine.executeAndGetResultAsString();

          if( result == null )

              System.out.println( "Execution failed: " + xqEngine.getLastErrorMessage() );

          else

              System.out.println( "Result is " + result );

      }

 

 

      public static void main(String[] args)

      {

          try

          {

              rxml = com.altova.raptorxml.RaptorXML.getFactory();

              rxml.setErrorLimit( 3 );

 

              ValidateXML();

              RunXSLT();

              RunXQuery();

          }

 

          catch( com.altova.raptorxml.RaptorXMLException e )

          {

              e.printStackTrace();

          }

 

      }

 

}

 

© 2017-2023 Altova GmbH