Christopher Klewes
Christopher Klewes

Reputation: 11435

extended xsd for xml with multiple namespaces

Hey, im trying to open my XML schema for different namespaces, this seems to work but all the default namespace elements now are invalid.

Thank you in advance. I'm trying to achieve the same schema extension mechanism as done in Spring (i.E.: spring-beans.2.5.xsd) they open the bean definition also for ##other and this works!

I added an example of these three files for easy access to a zip archive and uploaded it to the one-click-hoster rapidshare.

Whats my fault?

example-list.xsd

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

  <xs:import namespace="http://www.w3.org/XML/1998/namespace" />

  <xs:complexType name="ExampleListModelType">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:group ref="ExampleListGroup" />
    </xs:choice>
  </xs:complexType>

  <xs:group name="ExampleListGroup">
    <xs:choice>
      <xs:element name="foo" type="xs:string" />
      <xs:element name="bar" type="xs:string" />
      <xs:element name="baz" type="xs:string" />
      <xs:any namespace="##other" processContents="strict" />
    </xs:choice>
  </xs:group>

  <xs:element name="action-list" type="ExampleListModelType" />
</xs:schema>

custom-example-list.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns="http://www.example.org/schema/custom" elementFormDefault="qualified"
 targetNamespace="http://www.example.org/schema/custom">
  <xs:element name="eek" type="xs:string" />
</xs:schema>

example-list.xml

<?xml version="1.0" encoding="UTF-8"?>
<action-list xmlns="http://www.example.org/schema/list" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:custom="http://www.example.org/schema/custom"
  xsi:schemaLocation="
    http://www.example.org/schema/list example-list.xsd
    http://www.example.org/schema/custom custom-example-list.xsd">
  <custom:eek></custom:eek>
  <bar></bar>
</action-list> 

The error

Invalid content was found starting with element 'bar'. One of '{foo, bar, baz, WC[##other:"http://www.example.org/schema/list"]}' is expected

Upvotes: 3

Views: 3453

Answers (2)

Jeff Walker
Jeff Walker

Reputation: 1704

Wow, that was a hard one. It's been a long time since I had to just keep making random-ish changes to xsd and validate to see what happens. :)

Add elementFormDefault="qualified" as an attribute to your <xs:schema> tag in example-list.xsd and it all validates. I'm still a bit confused as to why that is needed.

Upvotes: 3

xcut
xcut

Reputation: 6349

It looks like the problem is in your custom-example-list.xsd. You define the element "eek" to be in no namespace.

Change xmlns:balvi="http://www.example.org/schema/custom" to xmlns="http://www.example.org/schema/custom" in that schema.

Edit: Ok, so if you fixed that, here it gets tricky. The only thing I can think of is that because you specified ##other, only an element from outside your target namespace must appear there. But then you have this in a choice with elements from your target namespace. I cannot see anything in the spec that disambiguates this situation.

Perhaps you might want to change that choice to a simple sequence and see if it works then. If so, you know what's wrong. If it still breaks, it's possible that your schema include is failing.

Upvotes: 0

Related Questions