Search code examples
javaxmlnetbeansxsdxsd-1.1

How to use XSD 1.1 in Netbeans 8.2?


Netbeans seems to reject some XSD tags supported by XSD 1.1, for example "assert":

cvc-complex-type.2.4.a : Invalid content found from the element 'xs:assert'. One of the values '{"http://www.w3.org/2001/XMLSchema":attribute, "http://www.w3.org/2001/XMLSchema":attributeGroup, "http://www.w3.org/2001/XMLSchema":anyAttribute}' is expected. [205]

I tried to use some of these examples without success. What can I do to resolve my problem?

As far as I know, I have nothing to do to specify in the XSD schema that I use some features of XSD 1.1:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

Solution

  • It depends exactly what you mean by "use XSD 1.1 in NetBeans 8.2", but I assume you want to use the context menu entry Validate XML in NetBeans against some *.xsd file with XSD 1.1 features (such as assert). If I do that I see the same "cvc-complex-type.2.4.a : Invalid content found..." error that you report.

    There is no way to customize the validator used by the Validate XML command, and apparently it uses the JDK's javax.xml API for validation. NetBeans 8.2 uses Java 8, but even with JDK 9 there is no way to validate XSD 1.1 features:

    Java 9.

    ...The big news is that finally we get the internal ports of Xerces updated. Oracle (and Sun before them) have been really slack in neglecting this so long: Java was stuck using Xerces 2.7.n for 11 years for goodness sake. The new ports are equivalent to Apache Xerces 2.11.0. (NOTE: XSD is still 1.0 only, the XSD 1.1 updates have not been put in place, but this probably reflects Apache Xerces’ slow pace to make the changes official.)

    The same problem occurs when using Apache NetBeans 9.0 RC1 so this issue will probably not get resolved until either:

    • NetBeans uses a JDK which uses a version of Xerces that supports the validation of XSD 1.1 features.
    • NetBeans uses a different approach for XSD validation.

    I also don't see any NetBeans plugins that will help. Of course there are still third-party tools and (possibly) configuration for Maven projects that may help, but I don't see a solution using only NetBeans.