Question

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'>
    <child>1</child>
</root>
Was it helpful?

Solution

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'>
    <!-- the "edi" prefix is bound to http://ecommerce.example.org/schema
         for the "x" element and contents -->
</x>

OTHER TIPS

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

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

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top