Xsd String in XML
? XSD String in XML Schema
In XSD, the xs:string type is used to define elements or attributes that contain textual data.
? Basic Usage of xs:string
<xs:element name="firstName" type="xs:string"/>This means the firstName element can contain any sequence of characters.
? Example: String Element in XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstName" type="xs:string"/> <xs:element name="lastName" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>? Corresponding XML Document
<person> <firstName>John</firstName> <lastName>Doe</lastName></person>? Restricting Strings with XSD
You can restrict string content with:
minLengthandmaxLengthpattern(regular expressions)enumeration(allowed fixed values)
Example: Restricting a String
<xs:simpleType name="CodeType"> <xs:restriction base="xs:string"> <xs:minLength value="3"/> <xs:maxLength value="10"/> <xs:pattern value="[A-Z0-9]+"/> </xs:restriction></xs:simpleType><xs:element name="code" type="CodeType"/>This allows uppercase letters and digits only, between 3 and 10 characters.
Would you like me to generate a complete example combining these restrictions?