The < schema > element is the root element of every XML Schema. The < schema > element is the root element of each XML Schema: < schema > elements can contain attributes. An schema declaration often looks like this: The following code snippet: Shows that the elements and data types used in schema come 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 snippet: Shows that the elements defined by this schema (note, to, from, heading, body) come from the namespace: “ http://www.runoob.com ”. This snippet: Indicates that the default namespace is “ http://www.runoob.com ”.” This snippet: Indicates that elements used by any XML instance document and declared in this schema must be namespace qualified. This XML document contains a reference to XML Schema: The following code snippet: 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 “ http://www.runoob.com ”” namespace. Once you have the available XML Schema instance namespace: You can then use the schemaLocation property. This property has two values. The first value is the namespace that needs to be used. The second value is the location of the XML schema used by the namespace:< schema > element ¶
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.runoob.com"
xmlns="http://www.runoob.com"
elementFormDefault="qualified">
...
...
</xs:schema>
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.runoob.com"
xmlns="http://www.runoob.com"
elementFormDefault="qualified"
Reference Schema in an XML document ¶
<?xml version="1.0"?>
<note xmlns="http://www.runoob.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.runoob.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
xmlns="http://www.runoob.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.runoob.com note.xsd"