Hi.

I have been going through pubsub and noticed that it is really hard 
(impossible?) to extend it without editing the original schema. I am not XSD 
expert but as far as I know there is no way, for example, to add one attribute 
from own namespace to the schema with tools provided by XSD. The problem is 
that Pubsub schema defines all elements directly as named element and XSD 
allows extension or restriction only to named complex- or simple types.

There would be easy way around this by refactoring schema in following way.

Original publish element:
<xs:element name='publish'>
  <xs:complexType>
    <xs:sequence>
     <xs:element ref='item' minOccurs='0' maxOccurs='unbounded'/>
    </xs:sequence>
    <xs:attribute name='node' type='xs:string' use='required'/>
  </xs:complexType>
</xs:element>

Would translate to complex type definition named equally:
<xs:complexType name="publish">
  <xs:sequence>
    <xs:element name="item" type="item" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="node" type="xs:string" use="required"/>
</xs:complexType>

And refenrence to the complex type would be:
<xs:element name="publish" type="publish"/>

My own extension to publish could be something like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
xmlns:my="http://my.extension/my"; 
xmlns:pubsub="http://jabber.org/protocol/pubsub"; 
targetNamespace="http://jabber.org/protocol/pubsub";>
<xs:redefine schemaLocation="pubsub.xsd">
  <xs:complexType name="publish">
    <xs:complexContent>
      <xs:extension base="pubsub:publish">
        <xs:attribute ref="my:myownattribute" use="required"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:redefine>
</xs:schema>

Which would result publish element to have one new attribute from 
http://my.extension/my namespace.

I have refactored whole pubsub.xsd in this way if you are interested to see it. 
I am also open to suggestions how to do this without refactoring the original 
schema :)


Cheers,

Petri Liimatta

Reply via email to