Код: Выделить всё
2025-06-09T22:48:53.658+03:00 ERROR 374 --- [XBRL-validation-with-xsd_uses-xerces] [ main] rlValidationWithXsdUsesXercesApplication : Error: org.xml.sax.SAXParseException; systemId: file:/Users/rob.bram/work/test/XBRL-validation-with-xsd_uses-xerces/src/main/resources/xbrl/xbrl_001_valid.xml; lineNumber: 46; columnNumber: 51; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://sbr.gov.au/comnmdle/comnmdle.financialinstitutionaccount1.02.00.module":FinancialInstitutionAccount}'. One of '{"http://www.xbrl.org/2003/linkbase":schemaRef, "http://www.xbrl.org/2003/linkbase":linkbaseRef, "http://www.xbrl.org/2003/linkbase":roleRef, "http://www.xbrl.org/2003/linkbase":arcroleRef, "http://www.xbrl.org/2003/instance":item, "http://www.xbrl.org/2003/instance":tuple, "http://www.xbrl.org/2003/instance":context, "http://www.xbrl.org/2003/instance":unit, "http://www.xbrl.org/2003/linkbase":footnoteLink}' is expected.
< /code>
Я написал код, который работает с локальной копией всех задействованных xsds-он находится в GitHub: xbrlvalidationwithxsdusesxersApplication. < /p>
код валидатора: < /p>
@SpringBootApplication
public class XbrlValidationWithXsdUsesXercesApplication implements CommandLineRunner {
private static Logger log = LoggerFactory.getLogger(XbrlValidationWithXsdUsesXercesApplication.class);
public static void main(String[] args) {
SpringApplication.run(XbrlValidationWithXsdUsesXercesApplication.class, args);
}
@Override
public void run(final String... args) throws Exception {
// Compute path to the XBRL payload to be validated.
validateFile(Path.of("src/main/resources/xbrl/xbrl_001_valid.xml"));
validateFile(Path.of("src/main/resources/xbrl/xbrl_002_invalid-against-Schematron.xml"));
validateFile(Path.of("src/main/resources/xbrl/xbrl_003_invalid-against-XSD.xml"));
}
private static void validateFile(final Path xbrlPath) throws SAXException, IOException {
log.info("========== {} ==========", xbrlPath);
// 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";
log.debug("Attempted to resolve '{}' to '{}'.", systemId, 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()) {
log.info("'{}' is valid against '{}'.", xbrlPath, entryPointXsd);
}
for (SAXParseException error : errorHandler.getErrors()) {
log.error("Error: {}", error.toString());
}
}
public static final class XsdErrorHandler implements ErrorHandler {
// Removed for brevity.
}
}
Код: Выделить всё
[*]
Я мог бы потенциально отредактировать файлы xsd, но беспокойство о обслуживаемости и управлении версиями. />
Наиболее загадочный аспект этого - когда я полностью удаляю xmlcatalogresolver кода, Code, lefler_001, xbrl_00. Утверждает успешно.
Код: Выделить всё
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.debug("Attempted to resolve '{}' to '{}'.", systemId, resolvedSystemId);
return lsInput;
}
};
schemaFactory.setResourceResolver(resolver);
< /code>
Без приведенного выше кода я получаю: < /p>
2025-06-09T23:30:32.683+03:00 INFO 4615 --- [XBRL-validation-with-xsd_uses-xerces] [ main] rlValidationWithXsdUsesXercesApplication : 'src/main/resources/xbrl/xbrl_001_valid.xml' is valid against 'src/main/resources/xsd/sbr.gov.au/taxonomy/sbr_au_reports/sprstrm/sprcnt/sprcnt_0001/sprcnt.0001.conttrans.request.02.02.report.xsd'.
Подробнее здесь: https://stackoverflow.com/questions/796 ... d-xbrl-fil