Extending XUL Schema With Custom Tags

If you have custom widgets you created and need to include them in the schema the best way to do it is using redefine XSD element. This way original schema documents do not need to be changed. Most probably you would need a file per project where you would put all the redefines but there are other options too.

Simple Extension

<xs:schema
            targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:redefine schemaLocation="xul.xsd">
    <xs:group name="boxElementElementsOnlyGroup">
      <xs:choice>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:element ref="mycustomelement" />
      </xs:choice>
    </xs:group>
  </xs:redefine>
 
    <xs:element name="mycustomelement">
      <xs:complexType>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:attributeGroup ref="xulElementAttributes" />
      </xs:complexType>
    </xs:element>

</xs:schema>

Using redefine there is no need to change original xul.xsd schema.

More Complex Extension - 2 Files

One downside of redefine is you can use it only once so if you have more custom elements you have to put them all in one file or to split them and put redefine in one of them. Something like this:

file test1.xsd

<xs:schema
           targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:include schemaLocation="test2.xsd" />

  <xs:redefine schemaLocation="xul.xsd">
    <xs:group name="boxElementElementsOnlyGroup">
      <xs:choice>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:element ref="mycustomelement" />
        <xs:element ref="mycustomelement2" />
      </xs:choice>
    </xs:group>
  </xs:redefine>
 
    <xs:element name="mycustomelement">
      <xs:complexType>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:attributeGroup ref="xulElementAttributes" />
      </xs:complexType>
    </xs:element>

</xs:schema>

file test2.xsd

<xs:schema
            targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:include schemaLocation="xul.xsd" />

  <xs:element name="mycustomelement2">
    <xs:complexType>
      <xs:group ref="boxElementElementsOnlyGroup" />
      <xs:attributeGroup ref="xulElementAttributes" />
    </xs:complexType>
  </xs:element>

</xs:schema>

Most Flexible - 3+ files

Or have elements defined in multiple files and have one file that includes them all and does redefine. Something like this:

file test1.xsd

<xs:schema
            targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:include schemaLocation="xul.xsd" />

    <xs:element name="mycustomelement">
      <xs:complexType>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:attributeGroup ref="xulElementAttributes" />
      </xs:complexType>
    </xs:element>

</xs:schema>

file test2.xsd

<xs:schema
            targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:include schemaLocation="xul.xsd" />

  <xs:element name="mycustomelement2">
    <xs:complexType>
      <xs:group ref="boxElementElementsOnlyGroup" />
      <xs:attributeGroup ref="xulElementAttributes" />
    </xs:complexType>
  </xs:element>

</xs:schema>

file redefinexul.xsd

<xs:schema
            targetNamespace="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">

  <xs:include schemaLocation="test1.xsd" />
  <xs:include schemaLocation="test2.xsd" />

  <xs:redefine schemaLocation="xul.xsd">
    <xs:group name="boxElementElementsOnlyGroup">
      <xs:choice>
        <xs:group ref="boxElementElementsOnlyGroup" />
        <xs:element ref="mycustomelement" />
        <xs:element ref="mycustomelement2" />
      </xs:choice>
    </xs:group>
  </xs:redefine>

</xs:schema>

Summary

The first approach is good if you have only few elements. If things get more complicated and you have many custom elements that are easier to keep in separate files I would personally use the third approach.

Last edited Apr 21, 2009 at 8:33 PM by mlalevic, version 1

Comments

No comments yet.