Skip to content

Instantly share code, notes, and snippets.

@kornicameister
Last active December 11, 2015 18:38
Show Gist options
  • Save kornicameister/4643021 to your computer and use it in GitHub Desktop.
Save kornicameister/4643021 to your computer and use it in GitHub Desktop.
Text only (restricion included) with attributes
<!--
#################################################################
-->
<xs:annotation>
<xs:documentation>
This is the way to declare an element that may
contain text based child only along with attached
numerous of attributes.
Tke key is to define simpleType that defines
how the content of our element may look like
And when defining text only element provide mentioned
simpleType as the base for <xs:extension/> element
</xs:documentation>
</xs:annotation>
<xs:simpleType name="phoneNumberFormat">
<xs:restriction base="xs:string">
<xs:pattern value="\+\([0-9]{2}\)(-?[0-9]{2,3}){3}"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="phone">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="f:phoneNumberFormat">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="home"/>
<xs:enumeration value="office"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!--
#################################################################
-->
@kornicameister
Copy link
Author

<f:phone type="office">+(48)-654-65-65</f:phone>

works perfectly ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment