1. Trang chủ
  2. » Công Nghệ Thông Tin

Essential xml Quick Reference PHẦN 9 ppt

42 217 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 42
Dung lượng 711,67 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Element declarations appearing aspart of complex type definitions, either directly or through a group reference, are known as local element declarations.. Local element tions describe el

Trang 1

are known as global element declarations and can be referenced from

else-where in the schema or from other schemas Element declarations appearing aspart of complex type definitions, either directly or through a group reference, are

known as local element declarations Such element declarations are local to

the type in which they appear Global element declarations describe elements that

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:People' xmlns:tns='urn:example-org:People' >

Trang 2

Schema II

are always part of the target namespace of the schema Local element tions describe elements that may be part of the target namespace of the schemadepending on the values of the form attribute on the element declaration and thevalue of the elementFormDefault attribute on the schema element

declara-Attributes

being declared is abstract An abstract element may not appear in

an instance document; rather, an element in this element’s substitu-tion group must appear instead

mecha-nisms are prohibited for the element being declared The value of this attribute can be a list of one or more

value of this attribute overrides any schemawide default specified by a

not appear in place of this element either through use of xsi:type or substitution groups

not appear in place of this element either through use of xsi:type or substitution groups

for this element may not appear in place of this element

ele-ment whose type is a simple type

or a complex type derived from a simple type The default and

exclusive

Trang 3

final token None Specifies which derivation

mecha-nisms are prohibited for element declarations that are part of a sub-stitution group with this element declaration as the head The value

of this attribute overrides any mawide default specified by a

of this element may not be of a type derived by extension, either directly or indirectly, from the type

of this element

of this element may not be of a type derived by restriction, either directly or indirectly, from the type

of this element

with a type that is a simple type or

a complex type derived from a ple type The fixed and defaultattributes are mutually exclusive

declaration is qualified (in the target Namespace for the schema) or unqualified (in no namespace) The value of this attribute overrides any schemawide default specified by an

on the schema element This attribute may not appear on a glo-bal element declaration

qualified by the target namespace

of the schema

The element is unqualified

Trang 4

Schema II

times this element may appear in the context in which the declaration appears The value of this attribute may be any nonNegativeInteger

or the string unbounded This attribute may not appear on a glo-bal element declaration

nonNegative-Integer

times this element must appear in the context in which the declaration appears This attribute may not appear on a global element declaration

of the element being declared The name and ref attributes are mutu-ally exclusive

the element may have no content, provided it is annotated in the instance document with an xsi:nilattribute with a value of true

element declaration The enced element declaration may be

refer-in the same schema document as the referencing element declaration

or it may be in a different schema document, potentially in a different namespace This attribute may not appear on a global element decla-ration The ref and nameattributes are mutually exclusive

Trang 5

as the head of the substitution group to which this element decla-ration belongs This attribute can only appear on a global element declaration The referenced ele-ment declaration may be in the same schema document as the ref-erencing element declaration or it may be in a different schema docu-ment, potentially in a different namespace

being declared This attribute is a reference to a simple type or a complex type If the type and refattributes are both absent, then the element declaration may have a

its children, in which case the type

of the element is that anonymous inline type If no such children are present, then the type of the element

is the anyType in the namespace http://www.w3.org/2001/

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:People' >

Trang 6

Schema II

A global element declaration for an element with a local name of descriptionand a namespace name of urn:example-org:People This element isbased on the built-in string type

A global element declaration and several local element declarations

A global element declaration for an element with a local name of person and anamespace name of urn:example-org:People This element is based onthe Person complex type in the same namespace that has several local elementdeclarations A document conforming to this schema would have a document ele-ment with a local name of person in the urn:example-org:Peoplenamespace That element would have unqualified name and height children, inthat order The name element would contain a string and the height elementwould contain a double-precision floating point number

A global element declaration and a reference to the declaration

<xs:element name='description' type='xs:string' />

<xs:element name='name' type='xs:string' />

<xs:element name='height' type='xs:double' />

Trang 7

A global element declaration for an element with a local name of height and anamespace name of urn:example-org:Utilities and a reference to thatglobal element declaration The element is based on the built-in double type.Elements of type HeightVector must have a child element with a local name

of height in the namespace urn:example-org:Utilities

9.2.13 extension

<xs:extension base='QName' id='ID' >

<! all annotation anyAttribute attribute

attributeGroup choice group sequence

>

</xs:extension>

The extension element appears as part of a complex type definition and cates that the complex type is being derived by extension from some base type.The base type may be either a simple type or a complex type If the base type is

indi-a simple type, then the extended type mindi-ay only indi-add indi-attributes If the bindi-ase type is

a complex type, the extended type may add extra elements and/or attributes.When extra elements are added, these logically appear after the elements of thebase type, the resulting content model being the content model of the base typefollowed by the content model of the derived type with both parts treated as ifthey were wrapped in a sequence element Complex types with all as theirtop-level compositor cannot be extended by adding particles Only attributes can

be added to such types Similarly, an all group can only be used to extend atype that has an empty content model

Trang 8

Schema II

Attributes

Child elements

Examples

Extending a base type with a sequence compositor with another sequence

is derived If the parent of the extensionelement is a simpleContent element, then this attribute must refer to a simple type If the parent of the extension element is a

must refer to a complex type The base type may be in the same schema document as the derived type or it may be in a different schema document, potentially in a different namespace

Trang 9

Both types have sequence as their top-level model group Elements of typeEmployee must have name, height, and salary children, in that order They mayalso have an employeeNumber attribute

Extending a base type with a sequence compositor with a choice

The base type has sequence as its top-level model group whereas the derivedtype has choice Elements of type MaleFemalePerson must have name andheight children, in that order, followed by either a boybits element or agirlbits element

Trang 10

Schema II

Extending a base type with an all compositor

The base type has an all compositor The extended type adds an attribute tothe base type Elements of type Employee must have name and height children,

in any order They may also have an employeeNumber attribute

Extending a simple type

Trang 11

The extended type adds an attribute to the base type of string Elements oftype Employee may have a string of any length as their content They may alsohave a height attribute

Attributes

field This is always relative to the selector This attribute uses a subset of XPath that allows forms shown in the following table where x, y, and z are element names that may be qualified or unqualified, and a is an attribute name that may be qualified or unqualified The axis identifier child:: may appear in front of x, y, and z, and the axis identifier attribute:: may appear in place of the @ symbol

x/@a Attribute of child element

Trang 12

so on

Trang 13

Child elements

Example

A named model group

the particles in a referenced model group can appear in the referencing context The value of this attribute may be any

on a model group definition

Integer

1 Specifies the minimum number of times the

particles in a referenced model group must appear in the referencing context This attribute may not appear on a model group definition

group being defined This attribute may only appear on a model group definition

referenced model group may be in the same schema document as the referencing groupelement or it may be in a different schema document, potentially in a different namespace This attribute may not appear

on a model group definition

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:People' xmlns:tns='urn:example-org:People' >

<xs:group name='HeightAndWeightElems' >

<xs:sequence>

<xs:element name='height' />

Trang 14

schema being imported If this attribute is missing, then the schema being imported describes constructs that are unqualified

Trang 15

to be imported This attribute is just

a hint A schema processor may ignore the value of this attribute and retrieve a schema for the name-space specified by the namespaceattribute by other means

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:Base'

Trang 16

Schema II

Use of import

A schema document for the namespace urn:example-org:People that importsanother schema for the namespace urn:example-org:Base, as defined inthe previous example The import element specifies a schemaLocationattribute which the schema processor may or may not use to locate a schema forthe urn:example-org:Base namespace The PersonName type in theurn:example-org:Base namespace is used as the type of the name ele-ment in the type definition for Person

Trang 17

<xs:key id='ID' name='NCName' >

<! annotation field selector >

</xs:key>

The key element defines a named key made up of one or more element and/orattribute fields A key requires that the combination of fields must be unique Anyelement declaration referenced through a field child of a key element must not

document to be included

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:People' xmlns:tns='urn:example-org:People' >

Trang 18

Schema II

have a nillable attribute with a value of true A key can be referenced, via itsname, using the refer attribute of a keyref element, creating a referentialconstraint on the content of an instance document

Attributes

Child elements

Example

A key constraint

constraint

<xs:element name='id' type='xs:short' />

<xs:element name='name' type='xs:string' />

<xs:element name='creditlimit' type='xs:short' />

</xs:sequence>

</xs:complexType>

<xs:complexType name='WidgetOrder' >

<xs:sequence>

<xs:element name='id' type='xs:short' />

<xs:element name='numwidgets' type='xs:short' />

<xs:element name='customerid' type='xs:short' />

</xs:sequence>

</xs:complexType>

<xs:element name='customersandorders' >

Trang 19

The key element selects customer children of the customersandorders ment through the xpath attribute of the selector element The xpath attribute

of the field element then specifies that the id children of those customer ments must be unique; that is, no two customer elements can have the samevalue for their id child The key also has a name, CustomerID, so that it can berefered to from a keyref element

The keyref element selects order children of the customersandorders ment through the xpath attribute of the selector element The referattribute references the CustomerID key described earlier, and the xpathattribute of the field element then specifies that the customerid children of theorder elements identified by the selector must have a corresponding value inthe id elements identified by the key

Trang 20

Schema II

9.2.19 keyref

<xs:keyref id='ID' name='NCName' refer='QName' >

<! annotation field selector >

</xs:keyref>

The keyref element defines a referential constraint made up of element and/orattribute fields that refer to a key that is similarly made up of element and/orattribute fields The fields that make up the referential constraint are compared, inorder, with the fields of the key to which the referential constraint refers

The notation element denotes a notation declaration associating a name with

a public identifier and optionally a system identifier Notation declarations are ically used to deal with out-of-band binary data

keyref constraint

keyref refers

Trang 21

Child element

Example

Use of notation

declared

The syntax for public identifiers is defined in ISO-8879

often an executable capable of dealing with resources of this notation type

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:example-org:Pictures' xmlns:tns='urn:example-org:Pictures' >

<xs:notation name='jpg' public='image/jpeg'

system='display.exe' />

<xs:notation name='png' public='image/png' />

<xs:notation name='gif' public='image/gif'

Trang 22

Schema II

A schema with notations for several graphic formats and a complex type containing

a format attribute of type NOTATION This attribute would have a QName value

of tns:jpg, tns:png, or tns:gif in the instance document where the tnsprefix was mapped to the urn:example-org:Pictures namespace URI

9.2.21 redefine

<xs:redefine id='ID' schemaLocation='anyURI' >

<! annotation attributeGroup complexType group

simpleType >

</xs:redefine>

The redefine element is used to bring schema constructs such as elementdeclarations, complex and simple type definitions, and so forth, in an externalschema into a schema document and to redefine certain complex types, simpletypes, named model groups, and named attribute groups in the schema beingbrought in Such redefinitions appear inside the redefine element and must be

in terms of the type or group itself That is to say, complex types and simpletypes must name themselves as the base type, and named model and attributegroups must contain exactly one reference to themselves The redefined typesand named groups effectively overwrite the definitions in the original schemasuch that any references to those types and model groups now reference theredefined versions The target namespace of the redefined schema must matchthe target namespace of the including schema or it must be empty If the targetnamespace of the redefined schema is empty, then the constructs in that schemabecome part of the target namespace of the redefining schema document

document to be redefined

Ngày đăng: 12/08/2014, 16:22