Skip to content

Instantly share code, notes, and snippets.

@jstaerk
Created August 1, 2021 18:27
Show Gist options
  • Save jstaerk/dcc55eb40ec37d3a89d38334697094c3 to your computer and use it in GitHub Desktop.
Save jstaerk/dcc55eb40ec37d3a89d38334697094c3 to your computer and use it in GitHub Desktop.
Phive XRechnung validation erroring [SAX] cvc-elt.1.a: Deklaration des Elements "rsm:CrossIndustryInvoice" kann nicht gefunden werden.
plugins {
id 'groovy'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'com.helger.phive.rules:phive-rules-xrechnung:2.1.5'
implementation 'com.helger.phive.rules:phive-rules-en16931:2.1.5'
implementation 'com.helger.phive:phive-engine:7.2.0'
}
test {
useJUnitPlatform()
}
import java.io.File;
import java.util.Locale;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import com.helger.commons.error.IError;
import com.helger.phive.api.execute.ValidationExecutionManager;
import com.helger.phive.api.executorset.IValidationExecutorSet;
import com.helger.phive.api.executorset.VESID;
import com.helger.phive.api.executorset.ValidationExecutorSetRegistry;
import com.helger.phive.api.result.ValidationResultList;
import com.helger.phive.en16931.EN16931Validation;
import com.helger.phive.engine.source.IValidationSourceXML;
import com.helger.phive.engine.source.ValidationSourceXML;
import com.helger.phive.xrechnung.XRechnungValidation;
/**
* [error] [SAX] cvc-elt.1.a: Deklaration des Elements "rsm:CrossIndustryInvoice" kann nicht gefunden werden. (org.xml.sax.SAXParseException: cvc-elt.1.a: Deklaration des Elements "rsm:CrossIndustryInvoice" kann nicht gefunden werden.)
* [error] @ /schematron/1.3.3/cii/xslt/EN16931-CII-validation.xslt Failed to create JAXB context for package 'com.helger.schematron.svrl.jaxb' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@30946e09 (java.lang.IllegalArgumentException: Failed to create JAXB context for package 'com.helger.schematron.svrl.jaxb' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@30946e09)
* [error] @ /schematron/2.0.1/XRechnung-CII-validation.xslt Failed to create JAXB context for package 'com.helger.schematron.svrl.jaxb' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@30946e09 (java.lang.IllegalArgumentException: Failed to create JAXB context for package 'com.helger.schematron.svrl.jaxb' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@30946e09)
*/
public class Main
{
public static void main (final String [] args)
{
/** mvn process-sources did not help either */
System.out.println ("Hallo");
final ValidationExecutorSetRegistry <IValidationSourceXML> aVESRegistry = new ValidationExecutorSetRegistry <> ();
EN16931Validation.initEN16931 (aVESRegistry);
XRechnungValidation.initXRechnung (aVESRegistry);
System.out.println ("Finished VES Registry init");
if (false)
for (final IValidationExecutorSet <IValidationSourceXML> aves : aVESRegistry.getAll ())
{
System.out.println (aves.getID ().toString ());
}
final IValidationExecutorSet <IValidationSourceXML> aVES = aVESRegistry.getOfID (VESID.parseID ("de.xrechnung:cii:2.0.1"));
System.out.println ("VES found: " + aVES);
// final IValidationExecutorSet<IValidationSourceXML> aVES =
// aVESRegistry.getOfID(VESID.parseID("eu.cen.en16931:cii:1.3.0"));
if (aVES != null)
{
// Code for 6.x:
final ValidationExecutionManager <IValidationSourceXML> aVEM = new ValidationExecutionManager <> (aVES);
// What to validate?
try
{
final String dateiname = "01-02.xml";
final File xmlFile = new File (dateiname);
System.out.println (xmlFile.getAbsolutePath ());
System.out.println ("File exists: " + xmlFile.exists ());
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
final DocumentBuilder dBuilder = factory.newDocumentBuilder ();
final Document doc = dBuilder.parse (xmlFile);
System.out.println ("Read XML document: " + doc);
doc.getDocumentElement ().normalize ();
final IValidationSourceXML aValidationSource = ValidationSourceXML.create (null, doc.getDocumentElement ());
// Main execution
final ValidationResultList aValidationResult = aVEM.executeValidation (aValidationSource);
if (aValidationResult.containsAtLeastOneError ())
{
System.out.println ("errors found:");
for (final IError valRes : aValidationResult.getAllErrors ())
{
System.out.println (valRes.getAsString (Locale.ENGLISH));
}
}
else
{
System.out.println ("NO errors found ...");
}
}
catch (final Exception e)
{
System.err.println (e.getMessage ());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment