aspose file tools*
The moose likes Web Services and the fly likes xmlns vs. xmlns:xsi vs. xsi:schemaLocation vs. targetnamespace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "xmlns vs. xmlns:xsi vs. xsi:schemaLocation vs. targetnamespace" Watch "xmlns vs. xmlns:xsi vs. xsi:schemaLocation vs. targetnamespace" New topic
Author

xmlns vs. xmlns:xsi vs. xsi:schemaLocation vs. targetnamespace

Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
I am not getting actual functionality of all these practically:



Link inside xmlns is opening Oracle Website
Link xmlns:xsi opens w3c website with the message "This schema should never be used as such: the XML Schema Recommendation forbids the declaration of attributes in this namespace"
Link inside xsi:schemaLocation also opens Oracle's website

Does this solve any purpose in anything?

also, What is targetnamespace?

please share any link telling easy functionality of all these


Regards
Azrael Noor
Abhijit Durge
Greenhorn

Joined: Oct 31, 2012
Posts: 9
Hello,

Hope the following helps:

xmlns means if any tags in your xml are not prefixed with namespace then they belong to the default namespace which is the value of xmlns="blah"

xmlns:xsi means you have defined a namespace "xsi" and xsi:schemaLocation is the location of XSD.

targetNamespace is the means through which you can refer an xml tags within your own xml.

To elaborate lets take an example

The <product> and <order> tags will belong to default namespace i.e namespace defined by xmlns

In the <order> tag's attribute refersTo requires to point to Product p1 this is done via tns:p1 (targetnamespace and tns)

--
Regards,


g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 544
    
    3
I am not getting actual functionality of all these practically:


I said to myself if that many full-length pages out-there of tutorial and didactic nature fail to foot the bill of explaining the actual functionalities of all these, by what optimism can I expect to do any better in a forum of the kind calling for only reasonable concised answer? But something makes me change my mind and try nonetheless...

Link inside xmlns is opening Oracle Website

That is the wrong way to look at it (xmlns="..."). The right-hand-side is commonly told as a URI. It is by nature and by design meant exactly that: an identifier. Simply put a name syntactically conforms to certain rtf3986. There is no implication, none at all, that that name (identifier) can be resolved the way a URL, a "link" whatever it means, usually got resolved. Keep this in mind and you won't ever far from the truth. As to xmlns, the left-hand-side, I suppose you know the meaning of default namespace.

Link xmlns:xsi opens w3c website with the message "This schema should never be used as such: the XML Schema Recommendation forbids the declaration of attributes in this namespace"

Again the right-hand-side is understood exactly the same as what said above. Only this time, a short-hand for the identifier supposedly standing for a namespace's name is declared. When a fully-qualified name of an element or an attribute is called for in the document, the local-name is prefixed with the prefix (alias) followed by a colon. There won't be any ambiguity as to the colon because the local name of type NCName does not contain any colon therein.

Link inside xsi:schemaLocation also opens Oracle's website

This time, the error is flagrant. The xsi:schemaLocation means the document is declaring an attribute schemaLocation defined within the namespace of the alias xsi. Here, the right-hand-side is already of wrong, very wrong, syntactic construction. A validating process would raise exception and the validation would fail. What is the correct syntax? you have to consult the recommendation for the schema or any tutorial out-there.

Does this solve any purpose in anything?

First, the namespace declarations help to avoid the collision of vocabulary an xml document contains. That is not nothing already and is a very material instrument for achieving that. Second main point is that xsi:schemaLocation though is meant to indicate where the physical resource where the xsd document can be found to validate the xml document: it is by no means to coerce any validating application to resolve the url therein. It has only the suggestive nature and that is official (written to into the recommendation). Authors of a validating application have the full liberty to supply the url "linking" to the resouce which is the xsd document(s) to their liking. These are the main points.

also, What is targetnamespace?

targetNamespace itself, there is no recommendation constraining its use. Everybody is free to assign whatever meaning to it. There is no definite meaning of targetNamespace unless you spend reasonable effort in the question by saying in what context or well-known namespace that attribute is meant to live. I know what you have probably in mind, but the way it is asked implies you still have some gap to fill before asking.
 
 
subject: xmlns vs. xmlns:xsi vs. xsi:schemaLocation vs. targetnamespace