定制的XSD文件

问题描述:

我使用xsd文件来生成c#类,如来自Microsoft的xsd.exe。 我也从同一个xsd文件生成WPF表单。 在某些情况下,我需要在我的xs:element标签中定义自定义属性。 我使用这个属性来生成我的生成器来管理我的WPF表单中的某些功能。定制的XSD文件

我想要的是一些“高级”xsd文件,其中包含一些自定义属性。 它应该适用于任何xsd解析器。

像这样的myCutomAttribute:

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

我试图XSD文件与外部命名空间扩展, 但我不知道如何使它validable。我将名称空间generatorTools添加为gt。

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

这是谁应该扩展XSD:

<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> 

的事情是,如果我打字的属性GT:myCustomAttribute正确的,它的工作原理。 gt:myCustomAttribute的值将通过名为“functions”的extenal simpletype中的枚举进行验证。但是,如果我得到了输入错误,该属性将被接受任何值。但为什么?怎么做才能得到验证错误?

有效期:

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

无效:

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

这是有效的,但为什么?:

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

任何想法,任何解决方案,或即时通讯做完全地错了吗? 感谢您的帮助

PS .:英语不是我最好的语言。 ;)

希望我会小心并纠正你遇到的问题。 如果您要验证其他属性,例如myMissspelledAttribute像你的情况,你需要将必要的自定义属性添加到您的模式<xs:attribute name="myMissspelledAttribute" type="ns1:functions"/>

模式的样本如下所示

<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>