26.01.2019 Views

XML Simplified

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Module 2<br />

Namespaces<br />

2.2.6 Override Default Namespaces<br />

The default namespace applies to the element on which it was defined and all descendants of that<br />

element. If one of the descendants has another default namespace defined on it, this new namespace<br />

definition overrides the previous one and becomes the default for that element and all its descendants as<br />

demonstrated in the following code.<br />

Concepts<br />

Code Snippet:<br />

<br />

<br />

Evening in Paris<br />

$123<br />

<br />

<br />

Return to Earth<br />

$23<br />

Journey to the center of the Moon<br />

$123<br />

<br />

<br />

Notice that in the price element in the second book element a different namespace is provided. This<br />

namespace applies only to the price element and overrides the namespace in the catalog element.<br />

2.2.7 Best Practices for Using <strong>XML</strong> Namespaces<br />

Some of the best practices that are used for declaring <strong>XML</strong> Namespaces are as follows:<br />

‣ ¾ Namespaces should be properly planned.<br />

‣ ¾ Logical and consistent prefix names should be used for convenience while creating an <strong>XML</strong><br />

document.<br />

‣ ¾ Namespaces should be applied to a personal vocabulary, even when there is just one.<br />

‣ ¾ Namespaces should be used to separate or isolate elements that may otherwise seem similar.<br />

‣ ¾ When designing two vocabularies that have some elements in common, one namespace should<br />

be used to hold the common items.<br />

‣ ¾ HTTP URLs should be used for the URIs.<br />

<strong>XML</strong> <strong>Simplified</strong><br />

Version 1.0 © Aptech Limited

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!