Limit or limit the value used for the xsi: type attribute

I have the following xml fragment:

<MyField>
    <FieldName>Blah</FieldName>
    <ValueFormatting xsi:type="DateFormatter">
        <Format>dd/MM/yy</Format>
    </ValueFormatting>
</MyField>

In this XSD, how can I limit or limit the values ​​that are provided for an attribute xsi:typein a ValueFormatting element, since I have a list of four or five types that are valid (e.g. TextFormatter, NumberFormatter, DateFormatter, etc.)?

Also, in my XSD, how can I ensure that the attribute name is "xsi: type"? Is it right that I could probably get away with the attribute name “type”, but then I could risk a collision if the “type” is declared in other namespaces?

Thanks!

+3
source share
1 answer

"type", XSD .

, XML ( ), , XSD "targetNamespace" "type" . XML "xsi" ( "xsi" ), , , XML .

:

<xsd:element name="ValueFormatting">
  <xsd:complexType>
    <xsd:attribute name="type" minOccurs="1" maxOccurs="1" targetNamespace="http://...">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="TextFormatter" />
          <xsd:enumeration value="NumberFormatter" />
          <xsd:enumeration value="DateFormatter" />
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
    ...
  </xsd:complexType>
</xsd:element> 

<MyField> 
    <FieldName>Blah</FieldName> 
    <ValueFormatting xmlns:myns="http://..." myns:type="DateFormatter"> 
        <Format>dd/MM/yy</Format> 
    </ValueFormatting> 
</MyField> 
+3

Source: https://habr.com/ru/post/1719604/


All Articles