0

I'm new to xsd and learning about namespaces. Seen maximum all questions, blog etc but no one could help me understand in simple way.

What I have understood so far is that, Namespaces are used to differentiate elements having same names. (Not cleared about targetnamespace)

My understanding to make namespace is below

xlmns:foo()="URI" -->Namespace (Its a unique token I would say which is responsible to differentiate elements with this syntax. And this synatx given a name and the criteria of making that name is Prefix:ElementName-->Prefix.

I have got one example

<foo:tag xmlns:foo="http://me.com/namespaces/foofoo"  
         xmlns:bar="http://me.com/namespaces/foobar"  
         >  

  <foo:head>  
    <foo:title>An example document</foo:title>  
  </foo:head>  

  <bar:body>  
    <bar:e1>a simple document</bar:e1>  
    <bar:e2>  
      Another element  
    </bar:e2>  
  </bar:body>  
</foo:tag>

If we want to use multiple namespaces in a xsd then we can declare them once like in above example. Where same prefix is being used for multiple namespaces

foo:tag --->xmlns:foo="http://me.com/namespaces/foofoo" 
foo:tag --->xmlns:bar="http://me.com/namespaces/foobar

Is it same like in java where in a package we can have multiple classes and each class has its own attributes, in case of xml its elements. Am I correct ? Can anyone help me to understand TargetNamespace ?

Ravi
  • 30,829
  • 42
  • 119
  • 173
linuxman
  • 51
  • 8

1 Answers1

1

The targetNamespace is the namespace that is going to be assigned to the schema you are creating or the namespace that this schema is intended to target, or validate. It is the namespace an instance is going to use to access the types it declares.

For example :

<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.bestxml.com/jswbook/po">
...
</schema>

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

<purchaseOrder xmlns="http://www.bestxml.com/jswbook/po"
xmlns:addr="http://www.bestxml.com/jwsbook/addr">
  <accountName>Shanita</accountName>
  <accountNumber>123456</accountNumber>
  <addr:street>20 King St</addr:street>
</purchaseOrder>
Ravi
  • 30,829
  • 42
  • 119
  • 173