tags:

views:

34

answers:

1

I'm trying to make a simple xml-editor for some basic but specific needs, the thing that I'm not sure how to handle is that I want to be able to have own custom attributes (or something) in the xsd-schema itself.

Something like this is what I had in mind:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
   <xsd:element name="Book">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Author" type="xsd:string" listable="1" />
            <xsd:element name="Pages" type="xsd:int" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>

Where I want information about whether the element is 'listable' or not in the schema (note that the .xml file have no information or clue as to whether the element is listable or not, the listable attribute is just a way to organize the elements in the editor).

It doesn't need to be it's own attribute. If there's an misc attribute or something that I can play with that would be fine. Problem is just that the schema above doesn't validate (The 'listable' attribute is not supported in this context.)

Is there a way to store this kind of information in the schema?

Seems like it would be possible to create a new namespace but I don't know how that namespace should be declared so that any element may have a special attribute in the xsd (I'd rather avoid messing with the xml file for this). And it seems a bit overkill to create a new namespace just for this?

Or am I going about this the wrong way entirely?

+1  A: 

This information should sit in its own namespace. The best place to store it would be in an annotation on the attribute. You can attach an annotation to any schema item and they can contain xsd:documentation elements, designed for human readable documentation, and xsd:appinfo, designated for machine-processable information. So your example would look like:

 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://www.example.org/bar"&gt;
   <xsd:element name="Book">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Author" type="xsd:string" listable="1">
        <xs:annotation>
            <xs:appinfo>
                <foo:listable value="true"/>
            </xs:appinfo>
        </xs:annotation>
             </xsd:element>
            <xsd:element name="Pages" type="xsd:int" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>
Aled G
Thanks!Seems to be exactly what I need.
Magnus