Rules for forced namespace-qualifying of attributes

This Version: August 5, 2001

Latest Version: http://simonstl.com/ns/namespaces/attributes/

Previous Version: None

Editors:

Table of contents

  1. Introduction
  2. Rules
  3. Resources
  4. Normative References
  5. Informative References

1. Introduction

This vocabulary addresses problems created by the expectation that attributes without prefixes fall into the namespace of the element containing them (since they don't fall into the default namespace). Some vocabularies, notably RDF, are moving toward requirements that all attributes have explicit markup identifying the namespace to which they belong. It also provides a filter that will strip explicit namespace qualifications from attributes.

The com.simonstl.namespace.attributes.AttribNamespaceFilter will use this vocabulary to convert markup that looks like:

<p:person xmlns:p="http://simonstl.com/person" 
  givenName="Chip" familyName="Skillet" city="Ithaca"
/>

to:

<p:person xmlns:p="http://simonstl.com/person" 
  p:givenName="Chip" p:familyName="Skillet" p:city="Ithaca"
/>

Warning: use of this technique may change the meaning of your documents substantially. Use it with care after studying options and impact.

2. Rules

Attribute rules work the same way as element rules, though they are defined in the http://simonstl.com/ns/namespaces/attributes/ namespace and identify the namespaces on elements whose attributes should be qualified to match the element.

All of these examples will operate on this document:

<p:person xmlns:p="http://simonstl.com/person" 
  givenName="Chip" familyName="Skillet" city="Ithaca"
/>

The first set of rules converts attributes on elements in the http://simonstl.com/person namespace:

<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/">
<include nsURI="http://simonstl.com/person" />
</namespaces>

Applying this rule produces:

C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribFilterTester qualAtt1.xml atttest.xml
<?xml version="1.0" standalone="yes"?>

<p:person p:givenName="Chip" p:familyName="Skillet" p:city="Ithaca" 
xmlns:p="http://simonstl.com/person"></p:person>

The second rule converts attributes on elements in any namespace:

<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/">
<include nsURI="##any" />
</namespaces>

Applying this rule produces:

C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribFilterTester qualAtt2.xml atttest.xml
<?xml version="1.0" standalone="yes"?>

<p:person p:givenName="Chip" p:familyName="Skillet" p:city="Ithaca" xmlns:p="http://simonstl.com/person"></p:person>

The next set of rules specifies the namespace as an inclusion and then blocks it with an exclusion:

<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/">
<include nsURI="http://simonstl.com/person" />
<exclude nsURI="http://simonstl.com/person" />
</namespaces>

This rule effectively doesn't modify anything:

C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribFilterTester qualAtt3.xml atttest.xml
<?xml version="1.0" standalone="yes"?>

<p:person givenName="Chip" familyName="Skillet" city="Ithaca" xmlns:p="http://simonstl.com/person"></p:person>

The final rule accepts any namespace for this processing, but it excludes the http://simonstl.com/person namespace:

<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/">
<include nsURI="##any" />
<exclude nsURI="http://simonstl.com/person" />
</namespaces>

Again, blocking this particular namespace results in no modification of the original document:

C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribFilterTester qualAtt4.xml atttest.xml
<?xml version="1.0" standalone="yes"?>

<p:person givenName="Chip" familyName="Skillet" city="Ithaca" xmlns:p="http://simonstl.com/person"></p:person>

3. Related Resources

3.1 Document Type Definition

A DTD attqualrules.dtd.

3.2 SAX Filter

A SAX Filter implementing these rules. JavaDoc describing its class structure and usage is available here.

This code is as an example and is not normative.

3.3 JAR

The above code packaged as a java archive.

4. Normative References

  1. Extensible Markup Language (XML) 1.0
  2. W3C XML Names
  3. W3C XML Schema Part 1 - Structures

5. Informative References