Page 1 of 1

Validate XML against XSD generated by Oxygen

Posted: Fri Aug 21, 2020 6:01 pm
by Fiona Chen
Hello:

I use Oxygen to generate XSD. However, Oxygen hinted Error:

Code: Select all

The {target namespace} of an attribute declaration must not match 'http://www.w3.org/2001/XMLSchema-instance'.
This predicament causes me to comment out below:

Code: Select all

  <xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
If I comment out the subsequent referenced schema in the orignial XML:

Code: Select all

 <xs:attribute ref="xsi:schemaLocation" use="required"/>

Code: Select all

  <xs:attribute ref="xsi:type" use="required"/>
My Java API will fail the XSD validation, as the original XML referenced the import ns:

Code: Select all

 <value nullFlavor="OTH" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CD">
The Java API validation throws error:

Code: Select all

 cvc-elt.4.2: Cannot resolve 'CD' to a type definition for element 'value'.
I review below post but as the "CD" uses

Code: Select all

xmlns:xsi
, it wouldn't work.

topic616.html

Do you have a realistic solution for this problem?

Re: Validate XML against XSD generated by Oxygen

Posted: Tue Aug 25, 2020 11:06 am
by tavy
Hello,

We are using Trang to generate an XSD schema from XML files. It seems that Trang generates an xsi.xsd schema when you use attributes from "http://www.w3.org/2001/XMLSchema-instance" namespace. There is already an issue for this on the Trang project:
https://github.com/relaxng/jing-trang/issues/132

As an workaround you can remove the "xsi.xsd" schema import from your generated XSD schema. You need to delete the following line:

Code: Select all

<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
Best Regards,
Octavian