I have few questions about xml namespace, I will explain with these three pieces of code:
1 - Very simple XML Schema:
<?xml version="1.0" encoding="US-ASCII"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.library.com"
targetNamespace="http://www.library.com"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<element name="Book" type="tns:BookType" />
<complexType name="BookType">
<sequence>
<element name="Title" type="string" />
<element name="Author" type="string" />
</sequence>
</complexType>
</schema>
2 - XML that use the newly created xml schema:
<?xml version="1.0" encoding="US-ASCII"?>
<Book xmlns:xsi="http://www.wc3.org/2001XMLSchema-instance"
xsi:schemaLocation="http://www.library.com ex9.xsd"
xmlns="http://www.library.com">
<Title>Scherlock Holmes</Title>
Author>Arthur Conan Doyle</Author>
</Book>
3 - Another fragment code without relationship from the two above:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
....
</beans>
Question are:
- Why always are we declare namespaces like xmlns="http://www.w3.org/2001/XMLSchema" and xmlns:xsi="http://www.wc3.org/2001/XMLSchema-instance" but no schemaLocation for these is given?
- How an XML parser will know (for example for to validate) that
xmlns="http://www.w3.org/2001/XMLSchema" define elements like
<attribute>
,<complexType>
,<sequence>
, etc? - Reading many posts I understood that namespaces and thus their URI, means basically nothing, they are used just for avoid name conflicting. But I read also that if you declare xmlns="http://www.w3.org/2001/XMLSchema" namespace wrong the XML file will not valid, why?
- Why In the last code fragment always no schemaLocation is given for http://www.w3.org/2001/XMLSchema-instance.