/    Sign up×
Community /Pin to ProfileBookmark

How the property: “namespaceURI” works?

My studying for the subject: “namespace” object (through Microsoft’s and W3C’s documentation ended me to no understanding to the meaning/idea behind this member of JavaScript, specially due to lack of examples.
Would someone, please, show me through a little example how the property: “namespaceURI” works?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@7studOct 19.2004 — Hi,

I don't know much about namespaces in XML, but a namespace in any language is a way to prevent name 'collisions'. Lets say you have some XML like this:

<book>
<author>Paul Wilton</author>
<title>Beginning Javascript</title>
</book>

<director>
<name>Dr. Smith</name>
<title>Professor Emeritus</title>
</director>


If you want to refer to the <title> tag, you have a problem because there are two different title tags with two very different meanings and contexts. To prevent name collisions like that, you can define a namespace for each section of your code like this(this is psuedo code):
<i>
</i>-----------namespace1------------
&lt;book&gt;
&lt;author&gt;Paul Wilton&lt;/author&gt;
&lt;title&gt;Beginning Javascript&lt;/title&gt;
&lt;/book&gt;
---------------------------------
----------namespace2-------------
&lt;director&gt;
&lt;name&gt;Dr. Smith&lt;/name&gt;
&lt;title&gt;Professor Emeritus&lt;/title&gt;
&lt;/director&gt;
---------------------------------


Then you can refer to the specific <title> tag like this:

namespace1: <title>

namespace2: <title>

That way there is no ambiguity as to which tag you are refering to.

If you think about people working on large coding projects, with each person handling a section of the code, they might use the same names for variables, tags, etc. and that could cause big problems when the code is combined. But, if the project manager gives each programmer a unique namespace to use, which is a qualifier to the variable or tag name, then name collisions will be prevented.

See here for more details and examples:

http://www.rpbourret.com/xml/NamespacesFAQ.htm

I hope that helps. ?
Copy linkTweet thisAlerts:
@Lotfi_AbdolhalauthorOct 19.2004 — Hi Dear 7stud!

It is even greater than a help.

I am very gratefull to you.
×

Success!

Help @Lotfi_Abdolhal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...