Difference between xmlns and targetNamespace attributes

Hi,

[html]<?xml version="1.0"?>
<xsd:schema xmlns:xsd=“XML Schema
targetNamespace=“http://www.abc.com
xmlns=“http://www.abc.com
elementFormDefault=“qualified”>[/html]

Here, I understand that targetNamespace indicates that the elements declared in the schema will go in the “http://www.abc.com” namespace.

What is the significance of xmlns attributes? How xmlns attribute is different from targetNamespace attribute? :confused:

The target namespace is used for the internal referencing in the xml document to make sure it is valid as declared from the schema. The xmlns attribute actually declares the namespace of a particular element or group of elements.

In the example you have given: [html]xmlns=“http://www.abc.com”[/html]

[URL="http://www.abc.com/"]http://www.abc.com[/URL]

is the default namespace. You can tell it is the default by the lack of a prefix. This means any elements that are a child of this root element and do not have an explicit namespace declared will belong to this namespace. Any element belonging to the [html]xmlns:xsd=http://www.w3.org/2001/XMLSchema[/html] would have a prefix of XSD.

If both namespaces had prefixes then there is no default namespace and the elements would have either a prefix to designate which namespace they belong to or no prefix to designate that they have no namespace.

Here is a pretty good article from Oracle on the subject - http://www.oracle.com/technology/pub/articles/srivastava_namespaces.html

hope this helps

Thanks for the help Mark. The article is very helful.