Altova RaptorXML+XBRL Server 2024

The Java code listing below shows how basic functionality can be accessed. It is structured into the following parts:

 

Locate the examples folder, and create a RaptorXML COM object instance

Validate an XML file

Perform an XSLT transformation, return the result as a string

Process an XQuery document, return the result as a string

Run the project

 

This basic functionality is included in the files in the examples/API folder of the RaptorXML+XBRL Server application folder.

 

 

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