Two Laptop Bag*
The moose likes XML and Related Technologies and the fly likes What does xmlns:xsi mean? 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 "What does xmlns:xsi mean?" Watch "What does xmlns:xsi mean?" New topic
Author

What does xmlns:xsi mean?

Richard Butterwood
Ranch Hand

Joined: Nov 07, 2005
Posts: 45
Can someone explain what this actually does?

Is it the default namespace for the schema instance? Does it always have to be xsi?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It declares that the string that follows... xmlns:xsi="something"... will be the URI of a namespace, and that all elements (and attributes) that are in the scope of this declaration and have the prefix "xsi:" will belong to the namespace.

It's the namespace URI (the "something" part up there) that identifies whether it's describing schemas or auto part requisitions. The prefix (the "xsi" part) has no meaning by itself. It is an arbitrary string that is used to relate the namespace to the elements and attributes that belong to the namespace.

That having been said, it's also traditional to use certain prefixes for certain namespaces. For example it's traditional to use the prefix "xsl:" for the XSL transformation namespace "http://www.w3.org/1999/XSL/Transform".
Richard Butterwood
Ranch Hand

Joined: Nov 07, 2005
Posts: 45
So, does that mean it is not mandatory to have this in the XML definition? Virtually every example I have seen has xmlns:xsi at the top. A lot of XML files do not reference this xsi prefix either.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It isn't mandatory for XML documents to use namespaces.

But somehow I doubt that is your question. If your XML document contains a namespace declaration, that really doesn't mean anything except to a program that knows what to do with that namespace. For example you can use the XSL transform namespace in an XML document if you like, but most programs won't do anything special with it unless they are using the document to do XSL transformations.
Sameer Raza Ali
Greenhorn

Joined: Oct 15, 2009
Posts: 20
how does the xsi declaration actually work, is there a mapping to the url? like the way we use name space for a custom tag library and then it maps to tld file
the container knows where to search for the tld file (under WEB-INF folder)

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
Can i use any name space instead of the URL given above.

how does the schema validation actually work ??? would hihly appreciate an explanation
Thanks
Sameer



SCJP 1.4 , SCWCD 5.0
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Here's a link to the explanation as written in 1999 by the person who thought up the idea. It tells you everything you need to know.
Sameer Raza Ali
Greenhorn

Joined: Oct 15, 2009
Posts: 20
thanks Paul !!
Leon Omk
Ranch Hand

Joined: Aug 17, 2010
Posts: 75

If xsi is arbitrary(we can change it to xmlns:xsjkl), how about schemaLocation? Can I change it to xsi:schemaURL="..." ?


OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

No. Namespace prefixes are arbitrary. Element names are not, at least the local-name part is not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does xmlns:xsi mean?
 
Similar Threads
What is API?
NX:Rmi Help SOS
Reg web.xml
Ora.jar
String [ ] args