[*]Https://github.com/robertmarkbram/xbrlv ... pplication - verwendet Xerces.
https://github.com/robertmarkbram/xbrlv ... pplication - No Xerces, genau was im jdk. XSD-Dateien: < /p>
Code: Select all
package validate;
import java.io.IOException;
import java.nio.file.Path;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.xerces.util.XMLCatalogResolver;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@Slf4j
public class XsdValidatorTest {
public static void main(String[] args) throws SAXException, IOException {
// Compute path to the XBRL payload to be validated.
final Path xbrlPath = Path.of(
"/path/to/xbrl.xml"
);
final Source xmlStreamSource = new StreamSource(xbrlPath.toFile());
// Create objects to do the validation.
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Path xsdPath = Path.of(
"/path/to/sprcnt.0001.conttrans.request.02.02.report.xsd"
);
final Schema schema = schemaFactory.newSchema(xsdPath.toFile());
// Set up a CatalogResolver so that use the local XSD files and not look them up from the internet.
final String[] catalogs = { "xsd/catalog.xml" };
final XMLCatalogResolver resolver = new XMLCatalogResolver(catalogs);
schemaFactory.setResourceResolver(resolver);
// Create the validator.
javax.xml.validation.Validator validator = schema.newValidator();
// Capture the XSD errors so that we can report them back.
final XsdValidator.XsdErrorHandler errorHandler = new XsdValidator.XsdErrorHandler(xbrlPath);
validator.setErrorHandler(errorHandler);
// Validate and extract errors.
validator.validate(xmlStreamSource);
if (errorHandler.getErrors().isEmpty()) {
log.info("'{}' is valid against '{}'.", xbrlPath, xsdPath);
}
for (SAXParseException error : errorHandler.getErrors()) {
log.debug("Error: {}", error.toString());
}
}
}
Dies funktioniert gut, wenn sie mit dem Internet verbunden ist: < /p>
2025-04-14 22:00:53,043 [main] INFO validate.XsdValidatorTest [XsdValidatorTest.java:44] - main - '/path/to/xbrl.xml' is valid against '/path/to/sprcnt.0001.conttrans.request.02.02.report.xsd'.
[/code]
Schalten Sie nun das Internet aus und es schlägt fehl, ohne zu wissen, was xbrli: item ist.
Code: Select all
Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:/path/to/sprcnt.0001.conttrans.request.02.02.report.xsd; lineNumber: 82; columnNumber: 171; src-resolve: Cannot resolve the name 'xbrli:item' to a(n) 'element declaration' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
... snip
at java.xml/javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:628)
at validate.XsdValidatorTest.main(XsdValidatorTest.java:30)
FAILURE: Build failed with an exception.
< /code>
Mittwoch, 16. April 2025, 12:40:23 PM < /p>
Als Antwort auf @ghislain fournys Antwort.
< /code>
Ich habe verifiziert, dass der Pfad korrekt ist, aber ich erhalte immer noch genau das gleiche Ergebnis. SystemID: Datei: /Users/rob.bram/home/dev/superstream/sscore/src/main/resources/xsd/sbr.gov.au/taxonomy/sbr_au_reports/sprstrm/sprcnt/sprcnt_sprcnt.rport.rport. Leinenumberne: 82; ColumnNumber: 171; src-resolve: Der Name 'xbrli: item' in eine (n) 'Elementdeklaration' -Komponente kann nicht behoben werden. Wenn ich rewriteprefix
Code: Select all
final XMLCatalogResolver resolver = new XMLCatalogResolver(catalogs) {
@Override
public LSInput resolveResource(
final String type,
final String namespaceURI,
final String publicId,
final String systemId,
final String baseURI
) {
final LSInput lsInput = super.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
final String resolvedSystemId = (lsInput != null) ? lsInput.getSystemId() : "null";
log.info("Attempted to resolve '{}', resolved to: {}", systemId, resolvedSystemId);
return lsInput;
}
};
Code: Select all
...
< /code>
Ich erhalte immer noch das gleiche Ergebnis (funktioniert, wenn das Internet eingeschaltet ist, der gleiche Fehler, wenn das Internet ausgeschaltet ist). Ich sehe auch keine Ausgabe von xmlcatalogresolver < /code> und lasse mich sehr unklar, ob der Resolver verwendet wird. Ich musste Katalogeinträge des Formulars verwenden:
Code: Select all
// Create the schema factory.
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Tell the schema factory to use a catalog and resource resolver to use local XSD files.
final String[] catalogs = {"src/main/resources/xsd/catalog.xml"};
final XMLCatalogResolver resolver = new XMLCatalogResolver(catalogs) {
@Override
public LSInput resolveResource(
final String type,
final String namespaceURI,
final String publicId,
final String systemId,
final String baseURI
) {
final LSInput lsInput = super.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
final String resolvedSystemId = (lsInput != null) ? lsInput.getSystemId() : "null";
System.out.println("Attempted to resolve '" + systemId + "', resolved to: " + resolvedSystemId);
return lsInput;
}
};
schemaFactory.setResourceResolver(resolver);
// Create the validator using the XSD.
final String entryPointXsd = "src/main/resources/xsd/sbr.gov.au/taxonomy/sbr_au_reports/sprstrm/sprcnt/sprcnt_0001/sprcnt.0001.conttrans.request.02.02.report.xsd";
final Schema schema = schemaFactory.newSchema(new File(entryPointXsd));
javax.xml.validation.Validator validator = schema.newValidator();
// Add an error handler.
final XsdErrorHandler errorHandler = new XsdErrorHandler(xbrlPath);
validator.setErrorHandler(errorHandler);
// Validate and output errors.
final Source xmlStreamSource = new StreamSource(xbrlPath.toFile());
validator.validate(xmlStreamSource);
if (errorHandler.getErrors().isEmpty()) {
System.out.println("'" + xbrlPath
+ "' is valid against '" + entryPointXsd
+ "'.");
}
for (SAXParseException error : errorHandler.getErrors()) {
System.err.println("Error: " + error.toString());
}
< /code>
Dies ließ mich jedoch mit neuen Problemen zurück - die katalog.xml -Einträge waren nicht ausreichend und mussten angepasst werden. Ich habe immer noch Probleme mit dem Eintrag für XBRL-Linkbase-2003-12-31.xsd