aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes TargetNameSpace 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 "TargetNameSpace" Watch "TargetNameSpace" New topic
Author

TargetNameSpace

Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Hi,
Can any one tell me what is TargetNameSpace and what is the use of that.

Thanks in advance.


SCJP1.5(81%), SCDJWS(94%), next mission SCEA (but need to wait or that)
johaananan brownaaaa
Greenhorn

Joined: Dec 18, 2007
Posts: 22
targetNamespace is used to define a namespace for the document that you are defining it now.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
See namespace and targetnamespace
Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Hi Peer,
I still have doubt :
1.Is it necessary to have targetnamesapce and namepsace to be same(URI).
2.In your example Targetnamespace and namespace are both same so why did again we use namespace for purchaseOrder and Address.Is it it pinting to different location.
2.In the example we have used prefix only for namespace not for Target namespace. why so??

As far as understood TargetNamespace is like default namespace.I am in the right way?
Please help me in understaing it clearly.
Thanks in advance.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Divya Gehlot:
1.Is it necessary to have targetnamesapce and namepsace to be same


Not if you are not referencing anything that you are defining. As soon as your are trying to reference anything in that namespace it has to be the default namespace or a namespace with an assigned prefix.

xmlns="http://www.w3.org/2001/XMLSchema"
this means that {http://www.w3.org/2001/XMLSchema} is the default namespace - therefore any of the XML Schema elements don't need a prefix.

xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
assigns the "mh" prefix to the {http://www.Monson-Haefel.com/jwsbook} namespace. So whenever we refer an element or type that exists in that namespace we have to prefix it with "mh"

targetNamespace="http://www.Monson-Haefel.com/jwsbook"
this simply states that any elements and types that are defined by the Schema (or WSDL) are in created the {http://www.Monson-Haefel.com/jwsbook} namespace. It doesn't create a means for you to refer to anything in the {http://www.Monson-Haefel.com/jwsbook} namespace. This is why you have to use the "mh" prefix assigned by the namespace declaration when you are using mh:USAddress, mh:Book, mh:PurchaseOrder.

3.In the example we have used prefix only for namespace not for Target namespace. why so??

"xmlns" is a namespace declaration which can assign a prefix.
"targetNamespace" isn't a namespace declaration - it simply specifies the target namespace into which the new elements and types are defined into.

As far as understood TargetNamespace is like default namespace. I am in the right way?

No, that is incorrect.


However the default namespace can be the targetNamespace:

Now the default namespace is the target namespace. However now all of the XML Schema elements have to be prefixed with "xsd" - "xsd:schema", "xsd:complexType", "xsd:sequence" ...
[ February 29, 2008: Message edited by: Peer Reynders ]
Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Hi Peer,
Thanks alot for your explanation
Still I have some doubt
"targetNamespace" isn't a namespace declaration - it simply specifies the target namespace into which the new elements and types are defined into
What do you mean by "simply specifies the target namespace into which the new elements and types are defined into"
[ February 29, 2008: Message edited by: Divya Gehlot ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Divya Gehlot:
What do you mean by "simply specifies the target namespace into which the new elements and types are defined into"


XML Schema and WSDL files define new XML types and XML elements. Those types and elements must belong to a namespace. targetNamespace specifies which namespace that is.

Think of "targetNamespace" as what "package" is to Java. However you have to assign a targetNamespace - you cannot leave it blank.
Divya Gehlot
Ranch Hand

Joined: Sep 10, 2006
Posts: 243
Hi Peer,
Thanks a lot . Now its clear for me.
Your explaination really helped in understanding the namespaces.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: TargetNameSpace