my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes XML Namespace and XML Schema 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 » Engineering » XML and Related Technologies
Bookmark "XML Namespace and XML Schema" Watch "XML Namespace and XML Schema" New topic
Author

XML Namespace and XML Schema

Aravind Ravi
Ranch Hand

Joined: Oct 29, 2000
Posts: 34
In XML Schema, when we define the elements with the target namespace, does it imply that we are defining the name space with the elements defined in the schema?
Another clarification,
When we define an XML document like the following:

<xsl:root xmlns:xsl='http://www.w3.org/XSLT'>
<xsl:child>HELLO</xsl:child>
</xsl:root>

From the above it means that the elements root and child belong to
the namespace http://www.w3.org/XSLT. Right? How does an XSLT application(Transformer) really differentiate the elements that are inbuilt belonging to the w3c XSLT namespace and the elements that i have defined saying that it belongs to the w3c XSLT namespace. How is it said that these are the elements that are belonging to this namespace(from where will get the list of elements that are belonging to a particular namespace, and suppose i have my own domain and i want to associate some of my own tags(elements) to that namespace?)
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782

In XML Schema, when we define the elements with the target namespace, does it imply that we are defining the name space with the elements defined in the schema?


By associating a target namespace, you are simply telling the parser that the tags defined in the Schema belongs to the specified namespace. This will help the parser distinguish your symbols ie., yourNameSpace:YourTag elements from other tags that may be in the document having the same tag name ie., YourTag. Note that you are defining a new namespace by associating an URI with the namespace. This target namespace is not a resource that actually contains definitions of the tags used. It is simply an unique identifier, a kind of UUID.


When we define an XML document like the following:

<xsl:root xmlns:xsl='http://www.w3.org/XSLT'>
<xsl:child>HELLO</xsl:child>
</xsl:root>

From the above it means that the elements root and child belong to
the namespace http://www.w3.org/XSLT. Right? How does an XSLT application(Transformer) really differentiate the elements that are inbuilt belonging to the w3c XSLT namespace and the elements that i have defined saying that it belongs to the w3c XSLT namespace. How is it said that these are the elements that are belonging to this namespace(from where will get the list of elements that are belonging to a particular namespace, and suppose i have my own domain and i want to associate some of my own tags(elements) to that namespace?)

You are correct. Standard xsl tags are defined in the W3C namespace (http://www.w3.org/XSLT) which is some what like a default namespace for stylesheets. You can declare your own tags that belong to your own namespace and use them in the xsl document. Since xsl tags are already defined by W3C XSLT namespace, if you redefine the same tags your own namespace, it will not conflict the standard names since the namespace prefix would help the XSLT engine to distinguish between what you have defined and it understands as the "standard". Ofcourse, you give the XSLT a "hint" to resolve ambiguities by prefixing the tags with namespace. The ones that don't have any prefix naturally would be associated with the default namespace.
Hope that clarifies your doubts.
Cheers!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Aravind Ravi
Ranch Hand

Joined: Oct 29, 2000
Posts: 34
Hi Ajith,
Thanks a lot for your reply. It cleared my doubt to a certain extent. I have a my domain(which is a URI- to uniquely identify the namespace) say 'http://www.aravind.com'. Each namespace has a set of vocabulary. Right? When I write an XML document like this,
<aravind:root xmlns:aravind='http://www.aravind.com'>
Aravind Ravi
</aravind:root>

it just means that the element root is associated with the aravind namespace. It does not mean that the element root is now a part of the vocabulary of the aravind namespace.

Am I right in this understanding?

How do my expilicitly say that these are the set of elements(tag names) that can belong to my namespace? and ensure that in the XML document like the above case which has associated the root element to be belonging to my namespace, when I do not want the root element to be defined as a part of my namespace.
Where do I go and specify the list of elements that belong to mynamespace and ensure that no one else tampers with the list of elements(tags)in my namespace?

Thanks once again for your reply,
Aravind Ravi.
-----------------------------------------------------------------
Sun Certified Programmer for the Java2 Platform.
 
wood burning stoves
 
subject: XML Namespace and XML Schema
 
Similar Threads
Help needed on xmlns & targetNamespace
Namespaces in XML
Doubt in xsd
namespaces
Attempting to valiiate docbook with SAX/w3c schema