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

targetNamespace and default namespace

Nancy King
Ranch Hand

Joined: Jan 06, 2003
Posts: 30
Hi,
I am not clear about targetNamespace. Hope you can help me.
..
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
targetNamespace="http://www.Monson-Haefel.com/jwsbook">

<element name="address" type="mh:USAAddress"/>

<complexType name="USAddress">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
</sequence>
</complexType>
...


"targetNamespace declare the XML namespace of all NEW TYPES explicitly created within the schema"(from RMH book-p36).I understand that USAddress belongs to targetNamespace, because it is a new types created in the schema.
The schema also declare a default namespace. The namespace(default namespace) "is the standard namespace defined by the XML schema specification-all the XML schema elements must belong to this namespace"(from RMH book-p36).Does that mean "address","name" and "street" belong to the default namespace?
Thanks for your help.
Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
For the above schema

default namespace --> xmlns="http://www.w3.org/2001/XMLSchema"


address","name" and "street" are the element identifiers.

I would say address","name" and "street" are more like the class/instance variables in a Java Class, it can be any valid name.


targetnamespace is saying this is the namespace that these new element belong to.

Hope I did not confuse you :roll:


Thanks,
Santosh
Nancy King
Ranch Hand

Joined: Jan 06, 2003
Posts: 30
Santosh,

If I understand correctly, you mean "address", "name" and "street" element belong to targetNamespace, right? Then no element in above XML schema belong to default namespace. If that's true, no need to define default namespace in schema, am I right? I don't understand "all the XML schema elements must belong to this namespace(defult Namespace)"(from p36 of RMH book). In above XML schema, what are "XML schema elements"?
If above XML schema define elementFormDefault="qualified", then "name" and "address" in xml document must belong to targetNamespace, if no elementFormDefault defined, then "name" and "address" in xml document may not from targetNamespace. Am I right?
I am still confused, and please help me out.
Thanks,
Nancy
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
hope this helps.


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
vishal mehta
Greenhorn

Joined: Jun 07, 2004
Posts: 3
I have one question regarding targetNamespace.
Can we have more than one targetNamespace?
If yes then can someone give me an example?

Vishal
Slava Lovkiy
Greenhorn

Joined: Aug 17, 2005
Posts: 29
According to XML-Schema spec. (http://www.w3.org/TR/2004/PER-xmlschema-1-20040318/), we have the following definition of targetNamespace:
"[Definition:] Several kinds of component have a target namespace, which is either �absent� or a namespace name, also as defined by [XML-Namespaces]. The �target namespace� serves to identify the namespace within which the association between the component and its name exists. In the case of declarations, this in turn determines the namespace name of, for example, the element information items it may �validate�."
And there is a note in the same document:
"At the abstract level, there is no requirement that the components of a schema share a �target namespace�. Any schema for use in �assessment� of documents containing names from more than one namespace will of necessity include components with different �target namespaces�. This contrasts with the situation at the level of the XML representation of components, in which [i]each schema document contributes definitions and declarations to a single target namespace[i]."

Thus, single schema definition might address not more than 1 targetNamespace
ramesh vanka
Greenhorn

Joined: Mar 13, 2005
Posts: 11
TargetNameSpace: main purpose to identify uniqueness of the schema.

Here I had created 2 schemas 1) Default Name Space 2) Default Name Space and TargetName Space

1.xsd -- DefaultNameSpace
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="USAddress">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
</sequence>
</complexType>
</schema>

2.xsd -- TargetNameSpace
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNameSpace="http://rameshvanka.com/"
elementFormDefault="qualified">

<complexType name="USAddress">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
</sequence>
</complexType>
</schema>

Now I want to import the schema of 1.xsd and 2.xsd into my 3.xsd

But 1.xsd don't have targetName. it is not possible to import that schema, it don't uniqueness to identify the schema.

2.xsd have targetNameSpace, so that 3.xsd able to identify the target using the targetNameSpace of http://rameshvanka.com/

3.xsd:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ram="http://rameshvanka.com/"
targetNameSpace="http://megastar.com/"
elementFormDefault="qualified">

<import schemalocation="2.xsd"
namespace="http://rameshvanka.com/"/>

</schema>

Hope it will clear the all doubts on targetNamespace.











 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: targetNamespace and default namespace