tags:

views:

96

answers:

4

For instance, is the following XML document considered valid as per the W3C XML 1.0 recommendation? Notice that the namespace 'future' is not referenced anywhere in the document.

Although this may not be considered good style, my belief is that the document is still valid regardless of the unused namespace. Can anyone confirm or refute this assumption?

Thanks, Matt

<?xml version="1.0" encoding="UTF-8" ?>
<root xmlns='http://foo.org/v1'  xmlns:future='http://bar.org/v1'&gt;
 <child>1</child>
</root>
+3  A: 

No, it is not illegal to have unused namespace declarations in an XML document.

Josef
+1  A: 

W3C actually has a validator service. This validates with two warnings, encoding and lack of a doctype.

Charlie Martin
A: 

While most clean-up tools will remove unused namespaces I don't remember anything on XML spec saying it is illegal to keep them. And I don't know of any XML parser which won't accept such document (and there's a lot of such documents floating around).

drdaeman
Thanks. I'm working with a client who's development stack leaves a bit to be desired. Unfortunately it's XML implementation has a nasty habit of inserting unused namespace declarations.One of the vendors we're working with is rejecting any messages containing unused namespaces as being invalid as per the W3C specs. After spending the morning going through the recommendations I can't find any explicit rule stating this is illegal. However, I thought I might have overlooked something. Thanks for the input.
Matty
+3  A: 

The standard does not seem to indicate otherwise. Section 7, "Conformance of Documents" gives a few requirements in order to call a document "namespace-well-formed" and "namespace-valid" but nothing says that you can't have an unused namespace declaration.

In section 3, an example is given, which contains an unused namespace:

<x xmlns:edi='http://ecommerce.example.org/schema'&gt;
    <!-- the "edi" prefix is bound to http://ecommerce.example.org/schema
         for the "x" element and contents -->
</x>
Adam Batkin
Thanks Adam. That's pretty much exactly what I was looking for.
Matty