this is from w3school tutorial XML Schema
we have a notes.xsd as below
<?xml version="1.0"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
targetNamespace="
http://www.w3schools.com"
xmlns="
http://www.w3schools.com"
elementFormDefault="qualif
ied">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
w3 school says:
This fragment:
targetNamespace="
http://www.w3schools.com"
indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "
http://www.w3schools.com"
namespace.
We have a XML doc which uses the above XML Schema
<?xml version="1.0"?>
<note xmlns="
http://www.w3schools.com"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading
>
<body>Don't forget me this weekend!</body>
</note>
Q1)
what is xmlns in the <notes> tag above ?
we already know that notes , to, from etc are in the targetNamespace="
http://www.w3schools.com" ...which we already have set in the notes.xsd...so then what is this "xmlns" doing here in the xml document ?
w3school says :
The following fragment:
xmlns="
http://www.w3schools.com"
specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the "
http://www.w3schools.com"
namespace.
this is wrong ....all the lelemets declared in the targetNamespace in the XSD.
this is a confusing part ...can i skip this ?
Q2) see xsi:schemaLocation="
http://www.w3schools.com note.xsd"
very surprising ....we did not put the exact location here !!!
i think this should be the place where the xsd is kept ...is not it ?
xsi:schemaLocation="
http://www.w3schools.com c:\dump\note.xsd"
right ?
I am bit confused also as to why there is again a namespace inside schemaLocation ??
we already had a targetnamespace in the XSD ...is not it ?
Start Free Trial