Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outdated API Documentation for 1.5.0 #130

Open
SemikolonDEV opened this issue Apr 18, 2024 · 2 comments
Open

Outdated API Documentation for 1.5.0 #130

SemikolonDEV opened this issue Apr 18, 2024 · 2 comments

Comments

@SemikolonDEV
Copy link

SemikolonDEV commented Apr 18, 2024

The Description on https://github.com/itplr-kosit/validator/blob/main/docs/api.md is outdated and should be updated.

The code examples do not work with current version.

@SemikolonDEV SemikolonDEV changed the title Outdated API Description for 1.5.0 Outdated API Documentation for 1.5.0 Apr 18, 2024
@wustudent
Copy link

wustudent commented Aug 20, 2024

@SemikolonDEV I also experienced the same thing as you did. After some research by looking into the source code, I found out how we can set the Processor parameter to the build function: You can use de.kosit.validationtool.impl.xml.ProcessorProvider.getProcessor() to get a processor.

import static de.kosit.validationtool.config.ConfigurationBuilder.*;
import de.kosit.validationtool.api.Configuration;
import java.net.URI;
import java.nio.file.Path;

public class MyValidator {

 public static void main(String[] args) {
    Configuration config = Configuration.create().name("myconfiguration")
                          .with(scenario("firstScenario")
                                          .match("//myNode")
                                          .validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
                                          .validate(schematron("my rules").source("myRules.xsl"))
                                          .with(report("my report").source("report.xsl")))
                          .with(fallback().name("default-report").source("fallback.xsl"))
                          .useRepository(Paths.get("/opt/myrepository"))
                          .build(ProcessorProvider.getProcessor());
    Check validator = new DefaultCheck(config);
    // .. run your checks
 }
}

@fktrdui
Copy link

fktrdui commented Aug 22, 2024

Thanks @wustudent , your comment was very helpful for me as it was the first time I use the KoSIT validator.

I am writing the update code, which also worked for me:

public void run(Path testDocument) throws URISyntaxException {
       // Load scenarios.xml from classpath
       URL scenarios = this.getClass().getClassLoader().getResource("scenarios.xml");
       
       // Load the rest of the specific Validator configuration from classpath
       Configuration config = Configuration.load(scenarios.toURI()).build(ProcessorProvider.getProcessor());
       
       // Use the default validation procedure
       Check validator = new DefaultCheck(config);
       // Validate a single document
       Input document = InputFactory.read(testDocument);
       // Get Result including information about the whole validation
       Result report = validator.checkInput(document);
       System.out.println("Is processing succesful=" + report.isProcessingSuccessful());
       // Get report document if processing was successful
       Document result = null;
       if (report.isProcessingSuccessful()) {
           result = report.getReportDocument();

           // Other available methods of the report (Result object) are for example:
           System.out.println("Report: " + report.getReport());
           System.out.println("isAcceptable: " + report.isAcceptable());
           System.out.println("isSchemaValid: " + report.isSchemaValid());
           System.out.println("ProcessingErrors: " + report.getProcessingErrors());
       }
       // continue processing results...
   }

Note:
For the new users, loading scenarios(for XRechnung for example) from the class path will work with these steps:

  1. Download the latest XRechnung bundle from: https://xeinkauf.de/xrechnung/versionen-und-bundles/
  2. Unzip and locate the folder "validator-configuration-xrechnung_..."
  3. Copy the “scenarios.xml” file and “resources” folder to the root of your project under the “resources” folder (if not present, create the folder).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants