aspose file tools*
The moose likes XML and Related Technologies and the fly likes question relating to schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "question relating to schema" Watch "question relating to schema" New topic
Author

question relating to schema

David Spades
Ranch Hand

Joined: Feb 01, 2014
Posts: 208


1. Does the element must be <schema>?
2. What's the purpose of "target" namespace?
3. What's the purpose of targetNamespace attr?



1. Does the namespace must point to the same location as target in schema?
2. how does the schemalocation affect the physical file location?

thanks
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
Does this post help?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
David Spades wrote:


1. Does the element must be <schema>?

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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.
David Spades
Ranch Hand

Joined: Feb 01, 2014
Posts: 208
@paul: so what is your recommended format of namespace? thanks

@everybody:
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?
thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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.
David Spades
Ranch Hand

Joined: Feb 01, 2014
Posts: 208
thank for the reply. Can you please help with my second question?
thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

No, sorry, I don't know anything about Schema.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question relating to schema