views:

60

answers:

1

I have a project where a xsd document is loaded, and based on that a editor is created for each element. And then xml that implements that schema is loaded into the editor. This could be a simple textbox for a string, a datepicker for a date or a more complex data like a chapter with associated metadata.
The editor is generic so the editor has be generated based on the schema. For simple types ( like string and date) we can use the type attribute. But for more complex custom types we need to add a attribute to the xsd document that defines what editor subelement to use.

So I added a custom attribute called UIType, but this is not allowed by the w3 schema schema. Is there any way I can extend the w3 schema schema, prefably without making a copy of it and adding what I need, but actually extend it? Or is there another smarter way of doing this?

Thanks.

Just to make it clear; I do not want to add the attribute to the actual xml data, but to the schema.

Here is an example of the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
    <xs:element name="PublishDate" type="xs:date" />
    <xs:element name="Chapters">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="Chapter" UIType="ChapterPicker" >
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="ID" type="xs:int" />
                            <xs:element name="FileID" type="xs:int" />
                            <xs:element name="Title" type="xs:string" />
                            <xs:element name="Artist" type="xs:string" />
                            <xs:element name="Year" type="xs:int" />
                            <xs:element name="Timestamp" type="xs:string"  />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
+2  A: 

You already seem to be creating your extended types. You aren't limited to using "xs:int" or "xs:string" as the type. You can define your own types by extracting the complexType elements and naming them. You can then use their name as a type for other elements.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
    <xs:element name="PublishDate" type="xs:date" />
    <xs:element name="Chapters" type="Chapters_t" />
    <xs:complexType name="Chapters_t">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" name="Chapter" UIType="ChapterPicker" >
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="ID" type="xs:int" />
                        <xs:element name="FileID" type="xs:int" />
                        <xs:element name="Title" type="xs:string" />
                        <xs:element name="Artist" type="xs:string" />
                        <xs:element name="Year" type="xs:int" />
                        <xs:element name="Timestamp" type="xs:string"  />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
Ioan
Ahh frig, I think I even read about this on w3schools some time ago...I think this should solve the problem. I will give it go. I will give you the accept later once I tested it.
Lillemanden
It works. That was anoyingly simple. Thanks.
Lillemanden
You're welcome.
Ioan