XML Schema Tuto...login
XML Schema Tutorial
author:php.cn  update time:2022-04-20 14:13:02

XML schema element


XSD - <schema> Element The


<schema> element is the root element of every XML Schema.


<schema> element

<schema> element is the root element of every XML Schema:

<?xml version=" 1.0"?>

<xs:schema>
...
...
</xs:schema>

< The schema> element can contain attributes. A schema declaration often looks something like this:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http:// www.w3.org/2001/XMLSchema"
targetNamespace="//m.sbmmt.com"
xmlns="//m.sbmmt.com"
elementFormDefault="qualified" >
...
...
</xs:schema>

The following code snippet:

xmlns:xs= "http://www.w3.org/2001/XMLSchema"

Display the elements and data types used in the schema from the namespace"http://www.w3.org/2001/ XMLSchema". It also specifies that elements and data types from the namespace "http://www.w3.org/2001/XMLSchema" should use the prefix xs:

This fragment:

targetNamespace="//m.sbmmt.com"

Display the elements defined by this schema (note, to, from, heading, body) from the namespace: "http:// m.sbmmt.com".

This snippet:

xmlns="//m.sbmmt.com"

Indicates that the default namespace is "http:/ /m.sbmmt.com".

This fragment:

elementFormDefault="qualified"

Indicates that any element used by the XML instance document and declared in this schema must Qualified by namespace.


Referencing the Schema in the XML document

This XML document contains a reference to the XML Schema:

<?xml version="1.0"? >

<note xmlns="//m.sbmmt.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="//m.sbmmt.com note.xsd">

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The code below Snippet:

xmlns="//m.sbmmt.com"

Specifies the declaration of the default namespace. This declaration tells the schema validator that all elements used in this XML document are declared in the "//m.sbmmt.com" namespace.

Once you have the XML Schema instance namespace available:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

You can then use the schemaLocation attribute. This property has two values. The first value is the namespace to be used. The second value is the location of the XML schema used by the namespace:

xsi:schemaLocation="//m.sbmmt.com note.xsd"

php.cn