0

I have come across many xml configurations in struts , spring , ibatis etc. i used to use the declaration blindly coz im ignorant. I really want to know how this declarations are useful, is the one use being confirming to the DTD ?

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
Tito
  • 8,894
  • 12
  • 52
  • 86
  • 1
    No DTD there, its speficying an XSD. You can google the difference between XSDs and DTDs. There's an [SO question](http://stackoverflow.com/questions/2389760/dtd-vs-xsd-which-one-to-choose) about the differences if you are interested. – Ray Toal Nov 08 '11 at 10:14

1 Answers1

2

If you mean:

xmlns="http://www.springframework.org/schema/beans" and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

this are name spaces.

the line xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> is about where the name space declaration can be found.


From the comments:

why do we give them like that? is it for the xml syntax validation only? or some other extra purposes?

Assume you have two different XSD schemata that you want to use both in your XML. And both of them define a tag with the same name, but different meaning. Then an program that read your XML file need to understand which of the both tags you mean. So that is what the prefix (xsi) or what ever is used for.

The complete thing is used for validation, and editor support (auto completion). But also for stuff that is proceeding the XML without knowledge about the concrete semantics. (XLST for example.)

Ralph
  • 118,862
  • 56
  • 287
  • 383