15

When i am creating a spring project I always have problem with XLMNS. what is exactly XMLNS? what are these actually?

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

And where can I get the references for these? (resource of xmlns:xsi and xsi:schemeLocation.) is there any online manual for these? I can't seem to find them.

NOTE When I said references I meant the proper urls for them

UPDATED

Where can I see the XML namespaces for Spring beans, Spring Transactions, Spring MVC and such? and its schema locations?

user962206
  • 15,637
  • 61
  • 177
  • 270

3 Answers3

17

There is a good explanation here: what is the use of xsi:schemaLocation?

Here is springs docs on xsd config: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/xsd-config.html

NOTE: spring now recommend not to include the version number in the xsd unless specifically required, so you should have:

xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans.xsd"

and not:

xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"

"xmlns" defines the name space for the current element.

"xmlns:aop" defines the name space for elements within the current element, that have a prefix of "aop:"

Community
  • 1
  • 1
Solubris
  • 3,603
  • 2
  • 22
  • 37
3

These lines set up the namespaces for your XML document. Depending on what tags you are using in your XML file, you'll need the namespaces at the top (and references to the correct schemas) in order for the XML to be valid.

For example, if you are using the <aop/> tag in your bean definitions, you will need to reference the aop schema at the top of the file: xmlns:aop="http://www.springframework.org/schema/aop" If you aren't using that tag, you don't need that there.

For any namespaces you import, make sure you add a reference to the schema in the "xsi:schemaLocation" tag, like this: xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

I would recommend checking out a sample Spring application since it should have the bare minimum that you need to get something running.

JQ-
  • 390
  • 1
  • 6
  • don't they have any online references for these? instead of users guessing it? – user962206 Jul 24 '13 at 00:59
  • In XML, the namespace IDs are just keys that are local to the XML file. It's customary to pick ones that match (e.g., using `aop` for the AOP schema), but you could use `fdsa` if you wanted; you'd just have to use the `fdsa` prefix in all of your XML tags from that schema. – chrylis -cautiouslyoptimistic- Jul 31 '13 at 05:17
1

As far as answering the 'where is it documented', I think it depends per project. In the case of Spring, the project documentation does contain a reference to this information. As an example, check out the xsd-config section for Spring Framework 3.2.x: Appendix E. XML Schema-based configuration

Nizzo
  • 346
  • 2
  • 6