Generating Schema for existing xml file

This should cover W3C XML Schema, Relax NG and DTD related problems.
Nickmaster90
Posts: 2
Joined: Thu Apr 22, 2021 3:32 pm

Generating Schema for existing xml file

Post by Nickmaster90 »

Dear Oxygen Users,

I have an xml file which looks like follows

Code: Select all

<body>
<figure><figure><figDesc>1950er Jahre</figDesc></figure></figure></body>
I used the oxygen tool Creating Schema and got this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="body">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="figure"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="figure">
    <xs:complexType>
      <xs:sequence minOccurs="0">
        <xs:element ref="figure"/>
        <xs:element ref="figDesc"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="figDesc" type="xs:string"/>
</xs:schema>
After that, I want to validate the existing xml file against the newly created schema:

Code: Select all

<body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="DRG14test.xsd">
<figure><figure><figDesc>1950er Jahre</figDesc></figure></figure></body>
I get the error message that <figure> and <figDesc> are in the wrong place. Can anyone tell me what my mistake is?

Thank you!
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Generating Schema for existing xml file

Post by tavy »

Hello,

The generation does not work properly in this case. I think you need change the generated schema and set the "figure" and "figDesc" elements optional. Something like this:

Code: Select all

<xs:element ref="figure" minOccurs="0"/>
<xs:element ref="figDesc" minOccurs="0"/>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Nickmaster90
Posts: 2
Joined: Thu Apr 22, 2021 3:32 pm

Re: Generating Schema for existing xml file

Post by Nickmaster90 »

Thank you for your help, now it works!
Post Reply