0
votes

I use a xsd file to generate c# classes like xsd.exe from microsoft. I also generate WPF forms from the same xsd file. In some cases i need to define custom attributes in my xs:element tags. I use this attributes for my generator to manage some functionallity in my WPF Forms.

What i want is an "advanced" xsd file with some custom attributes on some elements. It should be valid for any xsd parser.

Like so for myCutomAttribute:

<xs:element name="mycustomName" type="someComplexType" myCutomAttribute="generateIndex">

I have tried to extend the xsd file with an external namespace, but i dont know how to make it validable. I added the namespace generatorTools as gt.

<xs:element name="mycustomName" type="someComplexType" gt:myCutomAttribute="generateIndex">

This is the xsd who should extend:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" 
xmlns:ns1="http://www.mycompany.com" 
targetNamespace="http://www.mycompany.com" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">
<xs:attribute name="myCutomAttribute" type="ns1:functions" />
<xs:simpleType name="functions">
    <xs:restriction base="xs:string">
        <xs:enumeration value="generateIndex"/>
        <xs:enumeration value="someOtherEntry"/>
    </xs:restriction>
</xs:simpleType>

The thing is, if i typing the attribute gt:myCustomAttribute right, it works. The value of gt:myCustomAttribute will be validated with the enumeration in the extenal simpletype named "functions". But if i got a typing error the attribute will be accepted with any value. But why? What is to do to get an validation error?

Valid:

<xs:element name="mycustomName" type="someComplexType" gt:myCutomAttribute="generateIndex">
<xs:element name="mycustomName" type="someComplexType" gt:myCutomAttribute="someOtherEntry">

Not valid:

<xs:element name="mycustomName" type="someComplexType" gt:myCutomAttribute="xyz123">

This is valid, but why?:

<xs:element name="mycustomName" type="someComplexType" gt:myMissspelledAttribute="xyz123">

Any ideas, any solutions, or im doing completly wrong? Thanks for help

PS.: english isnt my best language. ;)

1

1 Answers

0
votes

Hope I undersand correct what the problem you are getting. If you are going to validate another attribute, e.g. myMissspelledAttribute like in your case, you will need to add the necessary custom attribute into your schema <xs:attribute name="myMissspelledAttribute" type="ns1:functions"/>

The sample of the schema is shown below

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" xmlns:ns1="http://www.mycompany.com"
           targetNamespace="http://www.mycompany.com" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">
    <xs:attribute name="myCutomAttribute" type="ns1:functions"/>
    <xs:attribute name="myMissspelledAttribute" type="ns1:functions"/>
    <xs:simpleType name="functions">
        <xs:restriction base="xs:string">
            <xs:enumeration value="generateIndex"/>
            <xs:enumeration value="someOtherEntry"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>