Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

What does xmlns:xsi mean?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain what this actually does?

Is it the default namespace for the schema instance? Does it always have to be xsi?
 
Marshal
Posts: 26915
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 26915
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Paul Clapham
Marshal
Posts: 26915
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Paul !!
 
Ranch Hand
Posts: 75
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If xsi is arbitrary(we can change it to xmlns:xsjkl), how about schemaLocation? Can I change it to xsi:schemaURL="..." ?
 
Paul Clapham
Marshal
Posts: 26915
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Namespace prefixes are arbitrary. Element names are not, at least the local-name part is not.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic