XML Schema Part 0: Primer Second Edition - 0 views
-
<xsd:element name="comment" type="xsd:string"/>
-
ref="comment"
-
Global elements, and global attributes, are created by
declarations that appear as the children of theschema element. Once
declared, a global element or a global attribute can be
referenced in one or more declarations using therefattribute as described
above. - ...47 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
itemelement, and reference this group by name
in theitemelement 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 -
The instance document declares one namespace,
, and associates it with
http://www.example.com/PO1
the prefixapo:. This prefix is used to
qualify two elements in the document, namelyand
purchaseOrdercomment. The
namespace is the same as the target namespace of the schema
inpo1.xsd, and so a
processor of the instance document will know to look in
that schema for the declarations ofand
purchaseOrdercomment. In fact,
target namespaces are so named because of the sense in
which there exists a target namespace for the elements
purchaseOrderandcomment. Target
namespaces in the schema therefore control the validation
of corresponding namespaces in the instance. -
-
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 theattribute is set to
attributeFormDefault, appear prefixed in instance documents.
qualified -
he Namespaces in XML
specification does not provide a mechanism for defaulting
the namespaces of attributes -
the
formattribute can be applied
to an element declaration in the same manner -
we have omitted the
and
elementFormDefaultattributes in this example
attributeFormDefault
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 asxsd: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 thiselement is to bring in the definitions
include
and declarations contained in,
address.xsd -
The one important caveat to using
includeis that the target
namespace of the included components must be the same as
the target namespace of the including schema


