0

I am validating an XML doc in Java with Xerces, but don't get any errors.

However, the XML doc contains errors and when I validate it with for example XMLSply editor, the errors are correctly reported.

I can't find what I am doing wrong. I think I do include all XSD schemas that are required to validate correctly.

Please some advice? The code snippet:

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setErrorHandler(new ErrorHandlerDefault());
Schema schema = factory.newSchema(createSchemaSources());
validator = schema.newValidator().validate("file.xml");

The XSD's that I use to validate:

private Source[] createSchemaSources() throws IOException {
 Source[] sources = new Source[5];
 sources[0] = createSource("http://www.nltaxonomie.nl/7.0/domein/bd/tuples/bd-bedr-tuples.xsd");
 sources[1] = createSource("http://www.nltaxonomie.nl/7.0/basis/bd/items/bd-burgers.xsd");
 sources[2] = createSource("http://www.nltaxonomie.nl/7.0/domein/bd/tuples/bd-burg-tuples.xsd");
 sources[3] = createSource("http://www.nltaxonomie.nl/7.0/basis/sbr/types/nl-types.xsd");
 sources[4] = createSource("http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd");
return sources;
}

A small snippet of the xml file being validated (too big to list all):

<bd-burgers:CommutingExpensesDaysPerWeekCount unitRef="uu_513" contextRef="cc_711">2</bd-burgers:CommutingExpensesDaysPerWeekCount>

This entry contains an error, namely:

Numeric item <bd-burgers:CommutingExpensesDaysPerWeekCount> has neither a 'precision' nor a 'decimals' attribute.

This is correctly reported by XMLSpy but not by my Java code :(... So what am I doing wrong here? I though I was forgetting an XSD file, but "CommutingExpensesDaysPerWeekCount" is defined in "http://www.nltaxonomie.nl/7.0/basis/bd/items/bd-burgers.xsd", that is contained int he above xsd's, that corresponds to the type "nonNegativeIntegerItemType" contained in "http://www.nltaxonomie.nl/7.0/basis/sbr/types/nl-types.xsd", also contained in the xsd's above, and that extends "monetaryItemType" and is defined in "http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd", which xsd is also contained in the above validation.

Any idea why my Java validation not reports any errors?

BTW: it does report an error if I change the above XML snippet in:

<bd-burgers:CommutingExpensesAccordingToTableTotalAmount>841.0</bd-burgers:CommutingExpensesAccordingToTableTotalAmount>

That is: removing all attributes. I then get a correct Validation error saying that the contextRef is missing.

edbras
  • 4,145
  • 9
  • 41
  • 78

1 Answers1

1

XBRL is an application of XML, and, as such, XBRL has additional rules beyond XML that need to be followed if the document is to be considered a valid XBRL document. XBRL document validity is documented in the XBRL specification, available here. Because of this "extra layer" of rules, valid XML can be invalid XBRL. There are two layers of validation to be performed:

  1. Ensure that the document is a valid XML document.
  2. Ensure that the document follows all XBRL validation rules as documented in the XBRL specification.

Your Java code is simply parsing the XML, so it is performing the Level 1 validation (Ensure that the document is a valid XML document). Additional code is needed to perform the Level 2 validation (Ensure that the document follows all XBRL validation rules as documented in the XBRL specification).

My understanding is that XMLSpy can understand XBRL (as shown here), and can perform both levels of validation. The error you are seeing (Numeric item has neither ...) is an XBRL validation error that XMLSpy is specifically validating against all documents known to be XBRL documents.

If you are hoping to validate the XBRL document for validity, then you will need to make use of a Java-based XBRL validation engine that you can use in your code. If you are able to use .NET, I might recommend Gepsio, available here.

JeffFerguson
  • 2,952
  • 19
  • 28
  • Thanks. I am aware of the different XBRl validation steps/levels, like FRIS, business constraints, etc.. However, I think that the error is a "normal" XSD validation error (like I am performing), how come you think this is a specific XBRL validation? I get this kind of errors also when performing normal XSD validation? I can't use Gespsio, but was planning to sue UBMatrix in the future (or parts of it) and use their DTS discovery and validation. I hope, however, better XBRL validation and DTS discovery open source projects will show up in the near future.. – edbras Aug 21 '13 at 14:59