Welcome to WebmasterWorld!
XML Namespaces are a big pain in the patootie.
Here is a very useful (and verbose) XML namespace FAQ [rpbourret.com].
You need to define your namespace as a valid URI (not necessarily URL) format.
Here are a couple of examples:
<rootelem xmlns="http://www.example.com" xmlns:misc="http://www.example.com/misc">
<?xml version = "1.0" encoding = "UTF-8"?>
<root xmlns:a="AAA" >
<www xmlns:b="BBB" />
< x xx xmlns:c="CCC">
</ x xx>
the question asks the five elements on lines 06 to 10 are local-name z. i need to identify the URI of the namespace of the element or why the element is not in a namespace.
my first thought was
line 6: <a:z /> is AAA
line 7: <b:z /> is BBB
line 8: <c:z /> is CCC
line 9: <d:z /> is DDD
but im not sure. any ideas please.
I don't think that you will be able to do this:
The reason is that it is not a child node of the element that declares the namespace URI:
I think that you need to actually need to declare the namespace URI in the element, thusly:
I'm also not sure that this is legal in XML:
< x xx xmlns:c="CCC">
</ x xx>
Spaces aren't allowed in element names.
the coding is fine, it is from an exercise. i didnt wrote it. ok ill ask a simple question first
what are the URI's of the code
Hmm...can you point me to the exercise? I'd like to have a gander at it myself. Maybe I need to learn a bit more about this stuff.
At first blush, I would look askance at any exercise that says that a space as the first character of an XML element name is OK [w3.org].
That namespace FAQ [rpbourret.com] is very, very good. I will be the first to admit that I am no namespace expert, but I haven't seen a namespace xmlns attribute [rpbourret.com] described in anything other than URI form [en.wikipedia.org]. But then, you learn something new every day, and I would be interested in learning a bit more about this. It sounds like XML is actually a bit more flexible than I'd thought.
the exercise is in a book, not on teh web. how do i send it to yoy
i put x x x because x xx doesnt appear on the forum, instead a < #*$! appears.
Ah. Got it. No worries, then. Thanks for clearing it up. No need to send me the book :) My apologies for being snarky. I understand.
As the FAQ says [rpbourret.com], all xmlns content needs to be in URI [w3.org] form.
This means either a valid URL, or some other URI scheme [w3.org]. You can use the URN [w3.org] scheme, but the URN is supposed to be registered, sort of like a domain name. This is why the URL form is the most popular. It guarantees a unique namespace. Namespace declarations need to be globally unique.
Also, a namespace, as declared by the xmlns "attribute," applies to an element, and all its descendants. That's why declaring a namespace in <www will not apply to the subsequent <b:z element, as the <www element has been closed. The only namespaces that apply to the elements are the ones declared in <root and the <#*$! element (It turns into a stream of gibberish because WebmasterWorld has these rather annoying filters on its content, and I guess it thinks that you want to cuss).
Namespaces cannot be legally declared as "AAA" etc., because that is not valid URI form.
I sincerely hope that this helps you out.
[edited by: cmarshall at 12:33 pm (utc) on Aug. 10, 2007]
thanks for the reply, helps understand better.
for arguments sake would line 6 AAA and line 8 CCC if it was well formed with proper URI. would 7 and 9 not be in a namespace because they are closed off.
what happens to the <z /> on line 10, does it have a URI and would it be the root URI.
|for arguments sake would line 6 AAA and line 8 CCC if it was well formed with proper URI. would 7 and 9 not be in a namespace because they are closed off. |
That is correct. FAQ [rpbourret.com] says that the scope of a namespace is the element on which it is declared (using the xmlns declarator) and the descendants of the element.
|what happens to the <z /> on line 10, does it have a URI and would it be the root URI. |
That is in the default namespace. It either has no namespace, or, if you declare a default namespace [rpbourret.com], it is in that namespace.