This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

targetNamespace and default namespace

 
Nancy King
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Nancy King
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hope this helps.
 
vishal mehta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.











 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic