XSD:
<?xml version='1.0'?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
</xs:schema>
XML:
<?xml version="1.0"?>
<elementarrel
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="elmeu.xsd">
...
</elementarrel>
Utilitzarem aquest format per les nostres activitats.
XSD:
<?xml version='1.0'?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://jgregor.cat">
...
</xs:schema>
XML:
<?xml version="1.0"?>
<elementarrel
xmlns="http://jgregor.cat"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jgregor.cat/elmeu.xsd">
...
</elementarrel>
Tenim simpleType i complexType:
Exemple XSD:
<element name="email">
<simpleType>
<restriction base="xsd:string" />
</simpleType>
</element>
<element name="getPreferences">
<complexType>
<sequence>
<element name="email" type="email" />
</sequence>
</complexType>
</element>
Exemple XML:
<getPreferences>
<email>john@nowhere.com</email>
</getPreferences>
Element arrel d'un Schema XML.
Continguts: include, import, annotation, redefine, attribute, attributeGroup, element, group, notation, simpleType, complexType
<schema
attributeFormDefault = (qualified | unqualified): unqualified
blockDefault = (#all | List of (extension | restriction | substitution) : ''
elementFormDefault = (qualified | unqualified): unqualified
finalDefault = (#all | List of (extension | restriction | list | union): ''
id = ID
targetNamespace = anyURI
version = token
xml:lang = language >
Content: ((include | import | redefine | annotation)*,
(((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
</schema>
Declara un element.
Pare: schema, choice, all, sequence
Contingut: simpleType, complexType, key, keyref, unique
<element
abstract = Boolean : false
block = (#all | List of (extension | restriction | substitution))
default = string
final = (#all | List of (extension | restriction))
fixed = string
form = (qualified | unqualified)
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
nillable = Boolean : false
ref = QName
substitutionGroup = QName
type = QName >
Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
</element>
Exemples:
<xs:element name="cat" type="xs:string"/>
<xs:element name="dog" type="xs:string"/>
<xs:element name="redDog" type="xs:string"
substitutionGroup="dog" />
<xs:element name="brownDog" type="xs:string"
substitutionGroup ="dog" />
<xs:element name="pets">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="cat"/>
<xs:element ref="dog"/>
</xs:choice>
</xs:complexType>
</xs:element>
Defineix un tipus simple, que determina les restriccions i la informació sobre els valors dels atributs o elements amb contingut només de text.
Pare: attribute, element, list, restriction (simpleType), schema, union
Contingut: annotation, list, restriction (simpleType), union
<simpleType
final = (#all | (list | union | restriction))
id = ID
name = NCName >
Content: (annotation?, (restriction | list | union))
</simpleType>
<restriction
base = QName
id = ID >
Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits |fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))
</restriction>
<list
id = ID
itemType = QName >
Content: (annotation?, (simpleType?))
</list>
<union
id = ID
memberTypes = List of QNames >
Content: (annotation?, (simpleType*))
</union>
Exemples:
<xs:simpleType name="freezeboilrangeInteger">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="listOfDates">
<xs:list itemType="xs:date"/>
</xs:simpleType>
<xs:attribute name="allframesize">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="roadbikesize"/>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="mountainbikesize"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
<xs:simpleType name="roadbikesize">
<xs:restriction base="xs:positiveInteger">
<xs:enumeration value="46"/>
<xs:enumeration value="52"/>
<xs:enumeration value="55"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="mountainbikesize">
<xs:restriction base="xs:string">
<xs:enumeration value="small"/>
<xs:enumeration value="medium"/>
<xs:enumeration value="large"/>
</xs:restriction>
</xs:simpleType>
Defineix un tipus complex, que determina el conjunt d'atributs i el contingut d'un element.
Pare: element, redefine, schema
Contingut: annotation, simpleContent, complexContent, group, all, choice, sequence, attribute, attributeGroup, anyAttribute
<complexType>
abstract = Boolean : false
block = (#all | List of (extension | restriction))
final = (#all | List of (extension | restriction))
id = ID
mixed = Boolean : false
name = NCName >
Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?,
((attribute | attributeGroup)*, anyAttribute?))))
</complexType>
Exemples:
<xs:complexType name='internationalShoeSize'>
<xs:simpleContent>
<xs:extension base='xs:decimal'>
<xs:attribute name='sizing' type='xs:string' />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
El tipus complex pot tenir contingut simple o contingut complex.
Conté extensions o restriccions en un element complexType amb dades de caràcters o un element simpleType com contingut i no conté elements.
Pare: complexType
Contingut: Opcional — annotation. Obligatori — Exactament un dels següents elements: restriction (simpleContent), or extension (simpleContent).
<simpleContent
id = ID >
Content: (annotation?, (restriction | extension))
</simpleContent>
<extension
base = Qname
id = ID >
Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
</extension>
<restriction
base = QName
id = ID >
Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?,
((attribute | attributeGroup)*, anyAttribute?))
</restriction>
Exemples:
<xs:element name="generalPrice">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="shoeSize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="sizing">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="US"/>
<xs:enumeration value="European"/>
<xs:enumeration value="UK"/>
<xs:enumeration value="Japan"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Conté extensions o restriccions en un tipus complex que només conté contingut mixtos o elements.
Pare: complexType
Contingut: Opcional: annotation. Obligatori: exactament un dels següents elements: restriction (complexContent), or extension (complexContent).
<complexContent
id = ID
mixed = Boolean >
Content: (annotation?, (restriction | extension))
</complexContent>
<extension
base = Qname
id = ID >
Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
</extension>
<restriction
base = QName
id = ID >
Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
</restriction>
Exemples:
<xs:complexType name="address">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="USAddress">
<xs:complexContent>
<xs:extension base="address">
<xs:sequence>
<xs:element name="state" type="USState"/>
<xs:element name="zipcode" type="xs:positiveInteger"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Declara un atribut.
Pare: attributeGroup, schema, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Contingut: annotation, simpleType
<attribute
default = string
fixed = string
form = (qualified | unqualified)
id = ID
name = NCName
ref = QName
type = QName
use = (optional | prohibited | required): optional >
Content: (annotation?, (simpleType?))
</attribute>
Exemples:
<xs:attribute name="mybaseattribute" type="xs:string" default="test" />
<xs:complexType name="myComplexType">
<xs:attribute ref="mybaseattribute"/>
</xs:complexType>
<xs:complexType name="myComplexType">
<xs:attribute name="mybaseattribute" type="xs:string" use="required"/>
</xs:complexType>
<xs:attribute name="myHolidayLocationTemperature">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="60"/>
<xs:maxInclusive value="95"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:simpleType name="Sizes">
<xs:restriction base="xs:decimal">
<xs:enumeration value="10.5"/>
<xs:enumeration value="9"/>
<xs:enumeration value="8"/>
<xs:enumeration value="11"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="shoeSizes">
<xs:simpleType>
<xs:list itemType="Sizes"/>
</xs:simpleType>
</xs:attribute>
Agrupa un conjunt de declaracions d'atributs perquè puguin ser incorporades com a grup per definicions de tipus complex.
Pare: attributeGroup, complexType, schema, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Contingut: annotation, attribute, attributeGroup, anyAttribute
<attributeGroup
id = ID
name = NCName
ref = QName >
Content: (annotation?), ((attribute | attributeGroup)*, anyAttribute?))
</attributeGroup>
Exemples:
<xs:attributeGroup name="myAttributeGroup">
<xs:attribute name="someattribute1" type="xs:integer"/>
<xs:attribute name="someattribute2" type="xs:string"/>
</xs:attributeGroup>
<xs:complexType name="myElementType">
<xs:attributeGroup ref="myAttributeGroup"/>
</xs:complexType>
<group
name= NCName
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
ref = QName >
Content: (annotation?, (all | choice | sequence))
</group>
<all
id = ID
maxOccurs= 1: 1
minOccurs= (0 | 1): 1 >
Content: (annotation?, element*)
</all>
<choice
id = ID
maxOccurs= (nonNegativeInteger | unbounded) : 1
minOccurs= nonNegativeInteger : 1 >
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1 >
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
Exemples:
<xs:element name="thing1" type="xs:string"/>
<xs:element name="thing2" type="xs:string"/>
<xs:element name="thing3" type="xs:string"/>
<xs:attribute name="myAttribute" type="xs:decimal"/>
<xs:group name="myGroupOfThings">
<xs:sequence>
<xs:element ref="thing1"/>
<xs:element ref="thing2"/>
<xs:element ref="thing3"/>
</xs:sequence>
</xs:group>
<xs:complexType name="myComplexType">
<xs:all>
<xs:element ref="thing1"/>
<xs:element ref="thing2"/>
<xs:element ref="thing3"/>
</xs:all>
<xs:attribute ref="myAttribute"/>
</xs:complexType>
<xs:complexType name="myComplexType">
<xs:group ref="myGroupOfThings"/>
<xs:attribute ref="myAttribute"/>
</xs:complexType>
<xs:complexType name="chadState">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element ref="selected"/>
<xs:element ref="unselected"/>
<xs:element ref="dimpled"/>
<xs:element ref="perforated"/>
</xs:choice>
<xs:attribute name="candidate" type="candidateType"/>
</xs:complexType>
<xs:element name="zooAnimals">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="elephant"/>
<xs:element name="bear"/>
<xs:element name="giraffe"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Hi ha dos tipus de caràcters que s'utilitzen en expressions regulars: metacaràcters i caràcters normals. Un metacaràcter és un dels següents caràcters:
. \ ? * + { } ( ) [ ]
Aquests caràcters tenen un significat especial en expressions regulars, però es poden escapar. Un metacaràcter escapat té el comportament d'un caràcter normal.
Veure aquest contingut i aquest altre.
. for any character at all
\d for any digit;
\D for any non-digit
\s for any white space (including space, tab, newline, and return);
\S for any character that is not white space
x* to have zero or more x's;
(xy)* to have zero or more xy's
x? to have one or zero x's;
(xy)? to have one or no xy's
x+ to have one or more x's; (xy)+ to have one or more xy's
[abc] to include one of a group of values (a, b, or c)
[0-9] to include the range of values from 0 to 9
A|B to have A or B in the content.
x{5} to have exactly 5 x's (in a row)
x{5,} to have at least 5 x's (in a row)
x{5,8} to have at least 5 and at most 8 x's (in a row)
(xyz){2} to have exactly two xyz's (in a row).
Tipus: