aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Differences between targetNamespace and default namespace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Differences between targetNamespace and default namespace" Watch "Differences between targetNamespace and default namespace" New topic
Author

Differences between targetNamespace and default namespace

xixi wang
Greenhorn

Joined: May 19, 2004
Posts: 10
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

Joined: May 02, 2002
Posts: 122
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

Joined: Jun 29, 2001
Posts: 77
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 (K.P.T)<br /> <br />Sun Certified Enterprise Architect,TOGAF 8 Certified,Certified Information System security Professional (CISSP),SCJDWS,SCWCD,SCJP,MCP
k.p thottam
Ranch Hand

Joined: Jun 29, 2001
Posts: 77
ignore the posting earlier , I was not thinking , need some coffee
shanita
Greenhorn

Joined: May 15, 2004
Posts: 19
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

Joined: Oct 31, 2003
Posts: 92
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


-- <br />Richard Monson-Haefel<br /><a href="http://www.Monson-Haefel.com" target="_blank" rel="nofollow">http://www.Monson-Haefel.com</a>
xixi wang
Greenhorn

Joined: May 19, 2004
Posts: 10
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

Joined: May 15, 2004
Posts: 19
I think you are right
[ May 20, 2004: Message edited by: shanita ]
Sam Ms
Greenhorn

Joined: Aug 23, 2012
Posts: 1
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
 
 
subject: Differences between targetNamespace and default namespace