0

Apologies if this is a repeat of an older question but I did attempt to find a similar question and didn't have any luck. I'm going through the tutorials at www.w3schools.com for writing XSDs and XMLs. I have a basic understanding of namespaces but my question -- why do many XSDs that I've seen contain a reference to http://www.w3.org/2001/XMLSchema?

For example:

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

Why do many people include xmlns:xs="htttp://www.w3.org/2001/XMLSchema? Is it because it allows them to use predefined elements, attributes and types such as xs:string, xs:complexType, xs:simpleType, xs:attribute?

Does referencing the w3.org namespace allow you to use built-in datatypes?

Thanks in advance

2 Answers 2

1

A schema document by definition must have an outermost element whose local name is "schema" and whose namespace URI is "http://www.w3.org/2001/XMLSchema". That can't be achieved unless it has a declaration of this namespace (which you misspelled "htttp...", by the way). Namespaces are used to distinguish different XML vocabularies; XSD is an XML vocabulary, and this is the namespace that distinguishes it.

The w3schools site, by the way, is not associated with W3C in any way. I find it a handy way of looking up simple reference information, but it's a hopeless way to learn new concepts. Get yourself a good book and do some bedtime reading.

2
  • Good catch. @Michael Kay do you have a good book recommendation? Feb 4, 2018 at 15:44
  • Both the Priscilla Walmsley and Eric van der Vlist books are excellent. I use both. Feb 4, 2018 at 22:21
0

If an XSD file doesn't reference this namespace and use the elements from it, it's not an XML schema definition.

4
  • Thank you for the speedy response, but could you elaborate more please? Also a follow-up related question. In the tutorial it mentions using the following: xmlns:xsi="w3.org/2001/XMLSchema-instance" to tell the XML parser that the XML document should be validated against a schema. Why wouldn't the simple use of a flag suffice? Feb 3, 2018 at 22:32
  • 1
    @user7406684 Do you understand what XML namespace are and what their purpose is? Feb 3, 2018 at 22:39
  • Sort of... Isn't it a way to avoid conflicts between things defined in your document versus some other document. For example if I have a XML document with information about students, I might have an ID element differentiating students but you might have a similar XML document with customers and their respective IDs. Namespaces would allow us to differentiate different IDs. Feb 4, 2018 at 1:18
  • Yes, but the important thing is that XML elements defined in standards (such as XML schema) are identified by their fully qualified name, which includes the namespace. So if you don't use the namespace, then as far as the XML parser is concerned, those are just random elements you defined, not the special elements from the standard. Feb 4, 2018 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.