XML Schema Part 0: Primer Second Edition - 0 views
-
<xsd:element name="comment" type="xsd:string"/>
-
Global elements, and global attributes, are created by declarations that appear as the children of the schema element. Once declared, a global element or a global attribute can be referenced in one or more declarations using the ref attribute as described above.
-
ref="comment"
- ...151 more annotations...
-
The declaration of a global element also enables the element to appear at the top-level of an instance document
-
if the two things are both types and you define one and XML Schema has defined the other, say you define a simple type called decimal, there is no conflict. The reason for the apparent contradiction in the last example is that the two types belong to different namespaces
-
we can create a named attribute group containing all the desired attributes of an item element, and reference this group by name in the item element declaration:
-
A schema can be viewed as a collection (vocabulary) of type definitions and element declarations whose names belong to a particular namespace called a target namespace. Target namespaces enable us to distinguish between definitions and declarations from different vocabularies.
-
When we want to check that an instance document conforms to one or more schemas (through a process called schema validation), we need to identify which element and attribute declarations and type definitions in the schemas should be used to check which elements and attributes in the instance document. The target namespace plays an important role in the identification process
-
<element name="purchaseOrder" type="po:PurchaseOrderType"/> <element name="comment" type="string"/>
-
The instance document declares one namespace, http://www.example.com/PO1, and associates it with the prefix apo:. This prefix is used to qualify two elements in the document, namely purchaseOrder and comment. The namespace is the same as the target namespace of the schema in po1.xsd, and so a processor of the instance document will know to look in that schema for the declarations of purchaseOrder and comment. In fact, target namespaces are so named because of the sense in which there exists a target namespace for the elements purchaseOrder and comment. Target namespaces in the schema therefore control the validation of corresponding namespaces in the instance.
-
To specify that all locally declared elements in a schema must be qualified, we set the value of elementFormDefault to qualified:
-
we can replace the explicit qualification of every element with implicit qualification provided by a default namespace
-
xml, all the elements in the instance belong to the same namespace, and the namespace statement declares a default namespace that applies to all the elements in the instance. Hence, it is unnecessary to explicitly prefix any of the elements.
-
Attributes that must be qualified, either because they are declared globally or because the attributeFormDefault attribute is set to qualified, appear prefixed in instance documents.
-
he Namespaces in XML specification does not provide a mechanism for defaulting the namespaces of attributes
-
we have omitted the elementFormDefault and attributeFormDefault attributes in this example to emphasize that their values are irrelevant when there are only global element and attribute declarations.
-
<element name="purchaseOrder" type="po:PurchaseOrderType"/> <element name="shipTo" type="po:USAddress"/> <element name="billTo" type="po:USAddress"/> <element name="comment" type="string"/> <element name="name" type="string"/> <element name="street" type="string"/>
-
n cases where a schema is designed without a target namespace, it is strongly recommended that all XML Schema elements and types are explicitly qualified with a prefix such as xsd: that is associated with the XML Schema namespace
-
without prefixes, then references to XML Schema types may not be distinguishable from references to user-defined types.
-
Element declarations from a schema with no target namespace validate unqualified elements in the instance document. That is, they validate elements for which no namespace qualification is provided by either an explicit prefix or by default (xmlns:).
-
As schemas become larger, it is often desirable to divide their content among several schema documents for purposes such as ease of maintenance, access control, and readability
-
<include schemaLocation="http://www.example.com/schemas/address.xsd"/> The effect of this include element is to bring in the definitions and declarations contained in address.xsd,
-
The one important caveat to using include is that the target namespace of the included components must be the same as the target namespace of the including schema
-
Bringing in definitions and declarations using the include mechanism effectively adds these components to the existing target namespace
-
it is possible to include more than one document using multiple include elements, and documents can include documents that themselves include other documents. However, nesting documents in this manner is legal only if all the included parts of the schema are declared with the same target namespace.
-
Instance documents that conform to schema whose definitions span multiple schema documents need only reference the 'topmost' document and the common namespace, and it is the responsibility of the processor to gather together all the definitions specified in the various included documents
-
1. In an instance document, the attribute xsi:schemaLocation provides hints from the author to a processor regarding the location of schema documents. The author warrants that these schema documents are relevant to checking the validity of the document content, on a namespace
-
The schemaLocation attribute value consists of one or more pairs of URI references, separated by white space. The first member of each pair is a namespace name, and the second member of the pair is a hint describing where to find an appropriate schema document for that namespace.
-
and so there is a noNamespaceSchemaLocation attribute which is used to provide hints for the locations of schema documents that do not have target namespaces.
-
2. In a schema, the include element has a required schemaLocation attribute, and it contains a URI reference which must identify a schema document. The effect is to compose a final effective schema by merging the declarations and definitions of the including and the included schemas.
-
<element name="shipTo" type="ipo:Address"/> <element name="billTo" type="ipo:Address"/>
-
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType>
-
<xsd:element name="quantity"> <xsd:simpleType>
-
2. In a schema, the include element has a required schemaLocation attribute, and it contains a URI reference which must identify a schema document. The effect is to compose a final effective schema by merging the declarations and definitions of the including and the included schemas.
-
The technique we use here to derive new (complex) address types by extending an existing type is the same technique we used in Complex Types from Simple Types (§2.5.1), except that our base type here is a complex type whereas our base type in the previous section was a simple type.
-
we indicate that the content models of the new types are complex, i.e. contain elements, by using the complexContent element, and we indicate that we are extending the base type Address by the value of the base attribute on the extension element.
-
When a complex type is derived by extension, its effective content model is the content model of the base type plus the content model specified in the type derivation. Furthermore, the two content models are treated as two children of a sequential group
-
to identify exactly which derived type is intended, the derived type must be identified in the instance document. The type is identified using the xsi:type attribute which is part of the XML Schema instance namespace.
-
The import mechanism that we describe in this section is an important mechanism that enables schema components from different target namespaces to be used together, and hence enables the schema validation of instance content defined across multiple namespaces.
-
When schema components are imported from multiple namespaces, each namespace must be identified with a separate import element. The import elements themselves must appear as the first children of the schema element. Furthermore, each namespace must be associated with a prefix, using a standard namespace declaration, and that prefix is used to qualify references to any schema components belonging to that namespace. Finally, import elements optionally contain a schemaLocation attribute to help locate resources associated with the namespaces
-
If present, the schemaLocation attribute is understood in a way which parallels the interpretation of xsi:schemaLocation in (1).
-
To import components that are not in any target namespace, the import element is used without a namespace attribute (and with or without a schemaLocation attribute)
-
<import namespace="http://www.example.com/IPO"/>
-
En el ejemplo, el autor/a importa el tipo SKU definido en otro documento schema.
1. Para importar tipos de datos, identificamos el espacio de nombres en el cual están definidos y asociamos dicho espacio de nombres con un prefijo. En el ejemplo:
xmlns:xipo="http://www.example.com/IPO"
2. Usamos el elemento "import" para identificar el espacio de nombres objetivo:
<import namespace="http://www.example.com/IPO"/>
Es conveniente incluir el atributo Schemalocation en la etiqueta "import" para indicar la ruta de accedo al fichero Schema que contiene el tipo importado.
3. En la instancia XML sólo es preciso indicar la localización del Schema que referencia a los demás empleados.
-
-
XML Schema has the concept of a list type, in addition to the so-called atomic types that constitute most of the types listed in Table 2.
-
The value of an atomic type is indivisible from XML Schema's perspective. For example, the NMTOKEN value US is indivisible in the sense that no part of US, such as the character "S", has any meaning by itself.
-
NMTOKENS is a list type, and an element of this type would be a white-space delimited list of NMTOKEN's, such as "US UK FR"
-
<xsd:simpleType name="listOfMyIntType"> <xsd:list itemType="myInteger"/> </xsd:simpleType>
-
<xsd:simpleType name="USStateList"> <xsd:list itemType="USState"/> </xsd:simpleType> <xsd:simpleType name="SixUSStates"> <xsd:restriction base="USStateList"> <xsd:length value="6"/> </xsd:restriction> </xsd:simpleType>
-
Note that it is possible to derive a list type from the atomic type string. However, a string may contain white space, and white space delimits the items in a list type, so you should be careful using list types whose base type is string.
-
The include mechanism enables you to use externally created schema components "as-is", that is, without any modification.
-
base="ipo:Address"
-
El tipo base y el extendido tienen igual identificador.
Fuera del elemento "redefine" cualquier intento de nombrar a dos tipos de datos usando el mismo identificador producirá un error.
Notar cómo el elemento "redefine" debe ser el primer hijo del elemento "schema" y encerrar al tipo de dato que redefinimos.
-
-
The redefine element acts very much like the include element as it includes all the declarations and definitions from the address.xsd file
-
Outside of the redefine element, any such attempt to define a complex type with the same name (and in the same namespace) as the base from which it is being derived would cause an error.
-
Now that Address has been redefined, the extension applies to all schema components that make use of Address
-
Substitution GroupsXML Schema provides a mechanism, called substitution groups, that allows elements to be substituted for other elements. More specifically, elements can be assigned to a special group of elements that are said to be substitutable for a particular named element called the head element. (Note that the head element as well as the substitutable elementsmust be declared as global elements
-
Elements in a substitution group must have the same type as the head element, or they can have a type that has been derived from the head element's type
-
<ipo:shipComment>
-
- no todos los elementos del grupo de sustitución han de aparecer en la instancia XML. - los indicadores minOccurs y maxOccurs del elemento cabecera deben ser adecuados al número de elementos de sustitución que permitamos aparecer (pueden aparecer tantos como el valor maxOccurs del elemento cabecera). - si maxOccurs así lo permite, puede aparecer el elemento cabecera y sus sustitutos.
-
-
Abstract Elements and TypesXML Schema provides a mechanism to force substitution for a particular element or type. When an element or type is declared to be "abstract", it cannot be used in an instance document. When an element is declared to be abstract, a member of that element's substitution group must appear in the instance document. When an element's corresponding type definition is declared as abstract, all instances of that element must use xsi:type to indicate a derived type that is not abstract.
-
Declaring an element as abstract requires the use of a substitution group. Declaring a type as abstract simply requires the use of a type derived from it (and identified by the xsi:type attribute) in the instance document
-
the redefine mechanism we describe here enables you to redefine simple and complex types, groups, and attribute groups that are obtained from external schema files. Like the include mechanism, redefine requires the external components to be in the same target namespace as the redefining schema,
-
schema authors will sometimes want to control derivations of particular types, and the use of derived types in instances.
-
to specify that for a particular complex type, new types may not be derived from it, either (a) by restriction, (b) by extension, or (c) at all.
-
The restriction value of the final attribute prevents derivations by restriction. Preventing derivations at all, or by extension, are indicated by the values #all and extension respectively
-
an optional finalDefault attribute on the schema element whose value can be one of the values allowed for the final attribute. The effect of specifying the finalDefault attribute is equivalent to specifying a final attribute on every type definition and element declaration in the schema.
-
When a simple type is defined, the fixed attribute may be applied to any of its facets to prevent a derivation of that type from modifying the value of the fixed facets.
-
eplacement by derived types can be controlled using the block attribute in a type definition
-
Preventing replacement by derivations at all, or by derivations-by-extension, are indicated by the values #all and extension respectively. As with final, there exists an optional blockDefault attribute on the schema element whose value can be one of the values allowed for the block attribute.
-
a mechanism that controls which derivations and substitution groups may be used in instance documents
-
The schemaLocation attribute value consists of one or more pairs of URI references, separated by white space. The first member of each pair is a namespace name, and the second member of the pair is a hint describing where to find an appropriate schema document for that namespace
-
there is a noNamespaceSchemaLocation attribute which is used to provide hints for the locations of schema documents that do not have target namespaces.
-
the include element has a required schemaLocation attribute, and it contains a URI reference which must identify a schema document.
-
the import element has optional namespace and schemaLocation attributes. If present, the schemaLocation attribute is understood in a way which parallels the interpretation of xsi:schemaLocation
-
Be sure that if you specify a value for only the minOccurs attribute, it is less than or equal to the default value of maxOccurs,
-
mechanism that enables schema components from different target namespaces to be used together, and hence enables the schema validation of instance content defined across multiple namespaces.
-
import elements optionally contain a schemaLocation attribute to help locate resources associated with the namespaces.
-
we indicate that the content models of the new types are complex, i.e. contain elements, by using the complexContent element, and we indicate that we are extending the base type Address by the value of the base attribute on the extension element.
-
the values represented by the new type are a subset of the values represented by the base type (as is the case with restriction of simple types).
-
Table 3 shows several examples of how element and attribute declarations within type definitions may be restricted