Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Differences between targetNamespace and default namespace

 
xixi wang
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In xml, what is the difference between the targetNamespace and the default namespace? And when do the elements in the file take the targetNamespace and when do they take the default namespace?

Thanks a lot!

Xixi
 
Lipman Li
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that you understand default name space, but targetnamespace.

targetnamespace is used in XML for the schema definition, schema is used to
govern the XML instances.

the targetnamespace specified in shema is probably became the default namespace in XML instance most time.
 
k.p thottam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unqualified elements , are automatically in the default name space , while those with the name space prefix use the namespace as per the qualification.
the difference is really only between the fact that one is implicit the other is explicit
 
k.p thottam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ignore the posting earlier , I was not thinking , need some coffee
 
shanita
Greenhorn
Posts: 19
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
targetNamespace is the namespace that is going to be assigned to the schema you are creating. It is the namespace an instance is going to use to access the types it declares. In the following code, the schema will be assigned to the namespace http://www.Monson-Haefel.com/jswbook/po


In an XML document instance, you declare the namespaces you are going to be using by means of the xmlns attribute. For example:


The default namespace here is http://www.Monson-Haefel.com/jswbook/po, which makes reference to the schema previously created. This namespace applies to the element that declares it, and its child elements, unles they are prefixed. In the example, all the elements belong to the default namespace, except addr:street. Since it is prefixed, it belongs to the addr namespace (xmlns:addr="http://www.Monson-Haefel.com/jwsbook/addr")
 
Richard Monson-Haefel
author
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An XML namespace gives the types defined in and XML schema a unique name - kind of like a sir name. In the US there are probably 10 million people named "John" so we use Sir names like "Smith" and middle names like "William" to distinguish one "John" from the next. You can think of element names as first names and XML namespaces as Sir names. (Its not a prefect analogy but it's illustrative).

Sometimes it's helpful to think of XML Namespaces as being similar to Java package names. When you create an XML Schema you are defining a type, just as a Java source file defines a type. The targetNamespace is the unique namespace of that type, just like the package name of a class defintion is the unique namespace of that type. In other words, declaring a targetNamespace in an XML Schema is the same as declaring a package name in a Java class file. It assigns the type(s) to a particular namespace.

The concept of a default namespace and a targetNamespace are orthogonal; they are separate concepts.

The default namespace has scope. If you create an XML document (be it an instance document, WSDL file, SOAP message or XML Schema) all of the elements are assumed to have unique namespaces. Usually, you will assign a prefix (a nick name) to each namespace and than tag elements that belong to that namespace with the prefix (e.g. <soap:Envelope> . However, it is possible to create a default namespace, which is the same as saying any elements without a prefix belong to a certain namespace. A default namespace is simply a namespace that is declared without a preface (e.g. xmlns="http://www.blue.com"). Default namespaces apply to the element in which they are declared and all of its children that do not use an explicit prefix.

You can override a default namespace by assigning a child element a different default namespace (e.g. xmlns="http:\\www.red.com") - that element and its children that do not have an explicit prefix will become part of the new default namespace.

I hope that helps. Tried to give you a couple different ways of thinking of things.


Richard
 
xixi wang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the replies. They've been very helpful.

On page 225 in Richard's book, in the schema for get_businessDetail, there is a xsd prefix which is not defined anywhere. Why is this or am I missing something?

Thank you very much!

Xixi
 
shanita
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right
[ May 20, 2004: Message edited by: shanita ]
 
Sam Ms
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi xixi wang..

xsd is nothing but "xml schema description.."

Its new to the guys who is not familar with spring ws...

Rock it by visiting spring homepage..

http://static.springsource.org/spring-ws
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic