Validate XML against XSD generated by Oxygen

This should cover W3C XML Schema, Relax NG and DTD related problems.
Fiona Chen
Posts: 17
Joined: Fri Aug 21, 2020 5:40 pm

Validate XML against XSD generated by Oxygen

Post 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?
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Validate XML against XSD generated by Oxygen

Post 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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply