Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question re: Purpose of targetnamespace ??

Status
Not open for further replies.

djbeta

IS-IT--Management
Apr 16, 2004
46
US
Hi there,

I've been reading lots of tutorials on XML and am having a really hard time understanding the basics of namespaces in a schema. From an example I found at W3C, could someone please tell me (in plain English) hopefully, what the differences between these three lines are ??

(1) <schema xmlns="(2) xmlns:po="(3) targetNamespace="
I think: (1) is specifying that the basic tags in this document are tags that adhere to those established by the guidelines at Is that right? by doing a xmlns= does that make it the default namespace so that you don't have to put a prefix before the elements ??

I think that (2) means that we're setting a new set of language specific to and indicating by xmlns:po that all of that language's elements must be prefixed by "po" according to the rules of this schema. (good so far???)

But, what on earth is (3) for ???? and how is it different from (2) ???


any advice you can offer to get me thinking clearly about this would be most appreciated. I guess I have a problem understanding what the 'target' is ??
I also get confused when I see several unique namespaces mentioned in a schema but only one targetnamespace... how/why is that??
 
targetNamespace (3) is the mechanism used to describe the namespace being used in the target document (that document being described by the schema) for the elements, etc. In other words, in order for the described document to be valid, it would (typically) have to declare the targetNamespace as its default namespace. (I say typically because the requirement is really that the namespace of the document's elements, etc, have to carry the correct namespace, which can be done with namespace alias as well.)

As is usually the case, the schema itself needs to use that same namespace as well, which is the reason for (2). And the default namespace (1) you have correctly determined.

Tom Morrison
 
Thank you! this helps a lot.. the only thing I don't seem to understand now is:

Why does the schema need to use the namespace of the XML document it describes?

It's not as if it is using elements from that XML document, is it ??

Aren't the elements used in the schema derived solely from <schema "
why/when would the schema need to use the elements from the target XML document? or is there some other reason the namespace needs to be defined?

thanks!!!
 
Why does the schema need to use the namespace of the XML document it describes?

Well, it doesn't always.

As an example of when it does need to use the same namespace, consider a schema that has a global type declaration, which will be included in the targetNamespace. When the schema wishes to use that type (for example, on the declaration of an element), it must use the correct namespace, which must be declared separately from the targetNamespace.



Tom Morrison
 
Considering the description of djbeta,(3) is the interface to filter the target document.It also means the first valid on the target doc,if id doesn't fit,then stop.If it does,then use the schema to handle the target doc.

Just a fresh xml learner opinion.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top