This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If you mean element by the root element commonly appeared in a (w3c xml) schema document, then absolutely. But that piece of element itself can pick up any meaning it is destined to mean. That being what you mean, then yes, it must be named "schema".
2. What's the purpose of "target" namespace?
"target" is a prefixed declared in the namespace declaration xmlns:target="...". This is said in order not to confuse with the targetNamespace attribute. But your meaning is clear. The purpose should be asked like this : what is the purpose of the namespace declaration xmlns:target="...". The purpose of such declaration is that within the schema document, sometimes not always, needs arise that the author(s) has to make reference to some top-level schema element (xs:element, xs:complexType, xs:simpleType etc...) defined in that namespace (which happens to be the targetNamespace of the schema itself, but it can be some other namespace(s), not as rarely happens as you might think). In that case, you need the prefix to construct a fully-qualified name to refer to it.
You can however conceive a schema simple enough not to have that happens. In that case, that kind of declaration may perfectly not be appearing. It is not a rule that it must be there as such with a namespace uri coincides with the targetNamespace. No.
3. What's the purpose of targetNamespace attr?
The targetNamespace attr is to declare to the users of the schema document that this schema is purporting to define vocabulary and grammar of that specific namespace. In the case of targetNamespace being absent, things can be more complicated. To simplify the first step perception, it means that schema document is to do the defining work for the null (or empty) namespace. If however you couple the piece of schema in a grand design layout, that can be more complicated in the interpretation. But leave that aside for the moment as it won't help, and rather it confuses the issue prematurely.
David Spades wrote:
1. Does the namespace must point to the same location as target in schema?
If you mean the "default" namespace declaration and that you mean the above schema is meant to validate this document instance, then yes.
2. how does the schemalocation affect the physical file location?
The schemaLocation does not force the users to have the schema document physical file being named name5.xsd nor its presence in the baseURL, whatever it means... It is good to have that happens, but it has no binding obligation the application using the schema to follow that setting. That is what the recommendation means by saying that "physical" location is just a "hint". The author of an application using the schema has the full control of where to get the validating schema rather than the name5.xsd sitting somewhere of some baseURL agreed upon. A "hint" may help and very often help a lot. But it does not mandate the application following it.
ps You've to use simple double quotes in the document where you use magic quotes.
David Spades wrote:1. Does the namespace must point to the same location as target in schema?
Just one more comment on this: A namespace declaration does not "point" to any location. Its value is simply a name, a unique string of characters, and not a reference to anything. In technical terms it's a URI (Uniform Resource Identifier) and not a URL (Uniform Resource Locator). For some reason which I don't quite understand, it is traditional to format namespace URIs as if they were URLs.
Joined: Feb 01, 2014
@paul: so what is your recommended format of namespace? thanks
Let's discuss about this question from SOAP web service perspective since I got this question because I was in the process of understanding SOAP web service in the first place. at this point, I'm under the impression that if I want to validate an XML document with an XSD, then the said XML document MUST have a namespace pointing to "http://www.w3.org/2001/XMLSchema-instance" (the URL must be exactly that, no other url is permitted) and the said namespace's schemaLocation is practically useless, since it's just a hint. Is this about right?
There's no need for schemalocation in the first place because the web service application will be the one doing the validation and the path of xsd is determined from inside the code. right?
I don't really have a recommendation. I notice that Microsoft often uses a URN as a namespace name, which is legitimate since a URN is a URI. Personally I find it less tempting to interpret a URN as an address of some information. But generally people seem to have adapted to the convention of using an HTTP URL as their namespace name, misleading as that might be.
Joined: Feb 01, 2014
thank for the reply. Can you please help with my second question?