tags:

views:

20

answers:

1

Hi, I'm trying to redefine the maxOccurs attribute of an element in a simple XML Schema using Eclipse's WTP plugin as my IDE.

File: widget1.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/widget"
  elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:tns="http://www.example.org/widget"&gt;

  <xsd:complexType name="WidgetType">
    <xsd:sequence>
      <xsd:element name="Name" type="xsd:string"/>
      <xsd:element name="ProductID" type="xsd:unsignedInt"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="Widgets">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Widget" type="tns:WidgetType" minOccurs="1" maxOccurs="65536"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>

File: widget2.xsd In this file I want to redefine the maxOccurs attribute for Widget to 10.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/widget" elementFormDefault="qualified"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org/widget"&gt;

  <xsd:include schemaLocation="widget1.xsd"/>

  <xsd:redefine schemaLocation="widget1.xsd">
    <xsd:complexType name="Widgets">
      <xsd:complexContent>
        <xsd:restriction base="Widgets">
          <xsd:sequence>
            <xsd:element name="tns:Widget" maxOccurs="10"/>
          </xsd:sequence>
        </xsd:restriction>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:redefine>

</xsd:schema>

However, validation fails on widget2.xsd and Eclipse reports this error

Multiple annotations found at this line:

    - src-resolve.4.1: Error resolving component 'Widgets'. It was detected that 'Widgets' has no namespace, but components with no target namespace are not referenceable from schema document 'file:///C:/Projects/Test/XMLSchema/Widget/widget2.xsd'. If 'Widgets' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'Widgets' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:///C:/Projects/Test/XMLSchema/Widget/widget2.xsd'.

    - src-redefine.5.b.d: 'restriction' does not have a 'base' attribute that refers to the redefined element, 'http://www.example.org/widget,Widgets'. <complexType> children of <redefine> elements must have <extension> or <restriction> descendants, with 'base' attributes that refer to themselves.

I tried replacing Widgets in the <redefine> with tns:Widgets hoping to get rid of the namespace error but that doesn't work either.

What does this error mean? And is what I'm trying to do possible at all?

Thanks for your help, Ashish

+1  A: 

Ok, I managed to figure this one out after a lot of trial and error! The problem seems to have been that in widget1.xsd the type for the Widgets element was being created as an anonymous local type. Once I separated the type into its own local WidgetsType it fixed the problem. I'd appreciate it if anybody could answer why. I'm pasting the modified files, maybe it'll help someone else.

File: widget1.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/widget"
  elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:tns="http://www.example.org/widget"&gt;

  <xsd:complexType name="WidgetType">
    <xsd:sequence>
      <xsd:element name="Name" type="xsd:string"/>
      <xsd:element name="ProductID" type="xsd:unsignedInt"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="WidgetsType">
    <xsd:sequence>
      <xsd:element name="Widget" type="tns:WidgetType" minOccurs="1" maxOccurs="65536"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="Widgets" type="tns:WidgetsType"/>

</xsd:schema>

File: widget2.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/widget"
  elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:tns="http://www.example.org/widget"&gt;

  <xsd:redefine schemaLocation="widget1.xsd">
    <xsd:complexType name="WidgetsType">
      <xsd:complexContent>
        <xsd:restriction base="tns:WidgetsType">
          <xsd:sequence>
            <xsd:element name="Widget" type="tns:WidgetType" maxOccurs="10"/>
          </xsd:sequence>
        </xsd:restriction>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:redefine>

  <xsd:element name="Widgets" type="tns:WidgetsType" />

</xsd:schema>
Praetorian