About Namespace in XML

XML allows you to create your own elements and attributes. XML also allows developers to combine XML document types. For example, you could embed into an XHTML document elements from a document type that you created. The following would be an example of embedding your own elements into an XHTML document, but there’s a possible problem; look at the bolded elements;


<IDOCTYPE html PUBLIC “-//w3c//DTD
XHTML 1.0 Strict //EN”
“Http: // www.w3.org/TR/xhtml 1/DTD/
<xhtml 1-strict.dtd”>
<html xmlns =http://www.w3.org/1999/xhtml>
<Head>
<title>working with Namespaces</title>
</head>
<body>
<h1>online Class offerings</h1>
<class>
<title>Introduction to XML </title>
<instructor>Chelsea Valentine</instructor>
</class>
<class>
<title>TCP/IP for Webmasters</title>
<instructor>Ed Tittel</instructor>
</class>
</body>
</html.

The bold lines illustrate the problem of element name conflicts. The first title elements belongs to the XHTML document type; however, the next two title elements belong to our own document type. The problem arises when the processor has to decide what to do with them. How does the processor know which t I t l e element is which? The answer is XML namespaces.

XML namespaces allow you to use an element from one document type (such as an XML document) and embed it in another document type (such as an XHTML document). Because namespaces uniquely identify a set of elements that belongs to a given document type, they ensure that there are no element name conflicts.

The namespace in the XML recommendation document is seen as a complement to the XML specification and can be found at www.w3.org/TR/REC-xml-names. The recommendation document defines a special syntax to identify namespaces. The document defines how a collection of elements can be given unique identifiers; therefore, no matter where an element is used, you can be sure that it belongs to the namespace.

There are two ways to define a namespace

Default namespace defines a name3space using the xml ns attribute without a prefix, and all child elements are assumed to belong to the defined namespace. XTHML uses the default namespace construct to define the XHTML namespace.

Local namespace Defines a namespace using the xml attribute with a prefix. When the prefix is attached to an element, it’s assumed to belong to that namespace’s

In both cases, you define a namespace using the xmlns attribute. The attribute’s value is the name that identifies the namespace. A namespace name can be a Uniform Resource Identifier (URI).

A URI can be a URL or a URN. Most times, you “l find URLs used. This may seem strange, but the namespace is only symbolic and does not point to a document or schema. The value should be unique.

A default namespace is considered to apply to the element where it’s declared and to all child elements that are not assigned to another namespace. You define the namespace as you would define an attribute.

 


.

SetApp - 100 Apps for everything you ever wanted to do on Mac

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________



 


FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

Copyright - © 2004 - 2019 - All Rights Reserved.