This section describes a tutorial example on how to assign schema location to a namespace used in the schema and the XML document.
If you decide to use namespace for your XML documents, then you need to respect the following rules:
1. The namespace must be specified in the XML Schema Definition (XSD) file using the "targetNamespace"
attribute on the "schema" root element as "targetNamespace="namespace_uri"".
2. Declare a new namespace prefix in the XML document called, "xsi", with a special attribute on the root element:
"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"".
This is needed to provide the namespace prefix "xsi" for the next change.
3. The namespace must be specified together with the schema location in the "schemaLocation" attribute
on the root element of the XML document as "xsi:schemaLocation="namespace_uri schema_url"".
4. If the namespace is used as the default namespace in the XML document, you can specify it with
the "xmlns" attribute as "xmlns="namespace_uri"" on the root element.
5. If the namespace is used with a prefix in the XML document, you can specify it with
the "xmlns:xx" attribute as "xmlns:xx="namespace_uri"" on the root element.
Now, let's add a namespace identified as "http://herongyang.com/xml" to hello.xsd and call it
hello_namespace.xsd: