Jump to content

URI


ckrudelux

Recommended Posts

So what I understand of what I read is what the URI don't point any where it's where to help the programmer to tell what the content of the namespace is, or does it have any other function?

Link to comment
Share on other sites

I assume you mean the namespace URI?Yes, it doesn't have to point anywhere. The XML parser doesn't even try to access the URI. The URI is simply used as a unique identifier for the namespace. It would be similar to prefixing element names with something, like the functions/classes in PHP, but with namespaces, the prefix can be anything you want, as long as its mapped to the same URI.

Link to comment
Share on other sites

The URI is the namespace. From the point of view of the parser, prefixes don't really exist. A node's full name is a namespaceURI/localName pair. Prefixes are just a syntax sugar, used to make writing out namespaced names in mixed documents easier to read and write by humans.Setting a namespace URI to a prefix is also called "mapping" a prefix to an URI, because there can be more than one prefix referencing the same namespace URI.

Link to comment
Share on other sites

The URI is the namespace. From the point of view of the parser, prefixes don't really exist. A node's full name is a namespaceURI/localName pair. Prefixes are just a syntax sugar, used to make writing out namespaced names in mixed documents easier to read and write by humans.Setting a namespace URI to a prefix is also called "mapping" a prefix to an URI, because there can be more than one prefix referencing the same namespace URI.
so why would I want to refer to different namespace's then it doesn't mean anything.. I mean the prefix is thats separates them right?
<element xmlns:prefix1="namespace" xmlns:prefix2="namespace">	<prefix1:element>		data	</element>	<prefix2:element>		data	</element></element>

Link to comment
Share on other sites

That code:

<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix1:element> data </prefix1:element> <prefix2:element> data </prefix2:element></element>

would be equivalent to writing out

<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix1:element> data </element> <prefix1:element> data </prefix1:element></element>

or

<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix2:element> data </prefix2:element> <prefix2:element> data </prefix2:element></element>

or

<element> <element xmlns="namespace"> data </element> <element xmlns="namespace"> data </element></element>

It's the URI that defines a namespace, not the prefix. But if you had

<element xmlns:prefix1="namespace1" xmlns:prefix2="namespace2"> <prefix1:element> data </prefix1:element> <prefix2:element> data </prefix2:element></element>

Then because the URIs are different, yeah, the prefix is used to explicitly target one URI or the other. In the case of this particular example, you could also have:

<element> <element xmlns="namespace1"> data </element> <element xmlns="namespace2"> data </element></element>

but that becomes less and less readable as your document grows, which is why prefixes are usually used.

Link to comment
Share on other sites

That code:
<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix1:element> data </prefix1:element> <prefix2:element> data </prefix2:element></element>

would be equivalent to writing out

<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix1:element> data </element> <prefix1:element> data </prefix1:element></element>

or

<element xmlns:prefix1="namespace" xmlns:prefix2="namespace"> <prefix2:element> data </prefix2:element> <prefix2:element> data </prefix2:element></element>

or

<element> <element xmlns="namespace"> data </element> <element xmlns="namespace"> data </element></element>

It's the URI that defines a namespace, not the prefix. But if you had

<element xmlns:prefix1="namespace1" xmlns:prefix2="namespace2"> <prefix1:element> data </prefix1:element> <prefix2:element> data </prefix2:element></element>

Then because the URIs are different, yeah, the prefix is used to explicitly target one URI or the other. In the case of this particular example, you could also have:

<element> <element xmlns="namespace1"> data </element> <element xmlns="namespace2"> data </element></element>

but that becomes less and less readable as your document grows, which is why prefixes are usually used.

Okay I think I got that.. so if I want to put them to work.. I select the by the namespace "URI" to only get the items from that namespace group?
Link to comment
Share on other sites

Basically, yeah.DOM has a few *NS() functions that accept a namespace URI as an argument, in addition to the local name, such as getElementsByTagNameNS() for example. It allows you to do just that - target elements that belong to a certain namespace, regardless of what the prefix is.

Link to comment
Share on other sites

Basically, yeah.DOM has a few *NS() functions that accept a namespace URI as an argument, in addition to the local name, such as getElementsByTagNameNS() for example. It allows you to do just that - target elements that belong to a certain namespace, regardless of what the prefix is.
Sounds like that is the next step thanks for clearing this up for me :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...