|
XML Home
XML Tutorial About XML XML Viewers XML Editors XML Documents XML Syntax XML Elements XML Attributes XML with CSS XML with XSL XML Namespace XML Local Namespace XML Default Namespace XML Entities XML Creating Entities XML CDATA DTDDTD IntroductionDTD DOCTYPE DTD Internal DTD External DTD Combined DTD FPI DTD Elements DTD Element Operators DTD Attributes DTD Attribute Default Values DTD Attribute Types DTD General Entities DTD Parameter Entities DTD Embedded Images XSLTXSLT IntroductionXSLT Example XSLT Syntax XSLT <template> XSLT <apply-templates> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XPathXPath IntroductionXPath Location Path XPath Location Path - Absolute XPath Location Path - Relative XPath Attributes XPath Axis XPath Node Test XPath Predicate XPath Node Set XPath Comparison Operators XPath Boolean Operators XPath Number Operators XPath String Functions Tutorial Summary XHTML Tutorial AJAX Tutorial |
XML NamespaceIn XML, a namespace is used to prevent any conflicts with element names. Because XML allows you to create your own element names, there's always the possibility of naming an element exactly the same as one in another XML document. This might be OK if you never use both documents together. But what if you need to combine the content of both documents? You would have a name conflict. You would have two different elements, with different purposes, both with the same name. Example Name ConflictImagine we have an XML document containing a list of books. Something like this:
And imagine we want to combine it with the following HTML page:
We will encounter a problem if we try to combine the above documents. This is because they both have an element called title. One is the title of the book, the other is the title of the HTML page. We have a name conflict. What we can do to prevent this name conflict is, create a namespace for the XML document. Example NamespaceUsing the above example, we could change the XML document to look something like this:
We have added the xmlns:{prefix} attribute to the root element. We have assigned this attribute a unique value. This unique value is usually in the form of a Uniform Resource Identifier (URI). This defines the namespace. And, now that the namespace has been defined, we have added a bk prefix to our element names. Now, when we combine the two documents, the XML processor will see two different element names: bk:title (from the XML document) and title (from the HTML document). Note: If you have defined your tags and attributes in a DTD, you will need to update your DTD in order to make the new element names legal. Enjoy this website?
Oh, and thank you for supporting Quackit! |
FREE Hosting!With every domain name you register with ZappyHost, you get FREE (ad supported) hosting.PLUS you get:
Featured Template:
(Build your websites in minutes!) Got a MySpace Page?Get "www.yourname.com" for your MySpace page. Learn how >>. |