permaculture playing cards*
The moose likes Product and Other Certifications and the fly likes namespaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "namespaces" Watch "namespaces" New topic
Author

namespaces

Avinash Mulye
Greenhorn

Joined: May 30, 2002
Posts: 22
I am realy frustrated with namespaces.
Can anyone tell me a one stop solution to study namespaces. A web-site/page will be the best.
For example take a look at this -
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
What is the difference between the "xmlns:xs" ,
"targetNamespace" & "xmlns" ?
I mean why do they need 3 and what is each one for ?
PLEASE HELP.
Avinash.
Avinash Mulye
Greenhorn

Joined: May 30, 2002
Posts: 22
Take a look at the description that w3schools has given -
The <schema> element may contain some attributes. A schema declaration often looks something like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
...
...
</xs:schema>

The following fragment:
xmlns:xs="http://www.w3.org/2001/XMLSchema"

indicates that the elements and data types used in the schema (schema, element, complexType, sequence, string, boolean, etc.) come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs: !!
This fragment:
targetNamespace="http://www.w3schools.com"

indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.
This fragment:
xmlns="http://www.w3schools.com"

indicates that the default namespace is "http://www.w3schools.com".
This fragment:
elementFormDefault="qualified"

indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
_________________________________________________
Mark it -
xmlns="http://www.w3schools.com" indicates that the default namespace is
"http://www.w3schools.com"
What does this mean !!!
Once you specify a namespace the why do you need default one ?
This is nightmare !
PLEASE HELP.
Avi
Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
Hi,
Check out the tutorial at www.xfront.com which has good stuff about schemas
-Shoba
Danl Thompson
Ranch Hand

Joined: Apr 04, 2001
Posts: 93
Namespaces, they say, are simple. However, I find them not. To my mind, a simple one page NS overview is out of the question.
NS may be applied to elements, attributes, and data-types. However, just because a name has a colon : in it, doesn't put it in a NS. On the other hand, a name without a : may still be in an NS. Oddly, colon is a valid starting character for names.
Elements with the same local name but different NS can co-exist in the same document. However, Attributes with the same local name, but different NS prefixes cannot co-oexist in the same Element.
NS definitions in Schemas are complicated by the schema attributes, targetNamespace, elementFormDefault, and attributeFormDefault, includes, imports, and redefines.
And NS prefixes don't mean much. I once thought the prefix WAS the NS, and that the URL was meaningless. But I was wrong.
So, there is much to learn, to mull over, and so forth, regarding NS. Learn slowly, and retain it all.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: namespaces
 
Similar Threads
Help needed on xmlns & targetNamespace
Confusion with namespace
Question about generating XSD
a question about XML schema and XML (newbie)
XML schema