XML Utils: XML names

Copyright © 1995-2005 Opera Software AS. All rights reserved. This file is part of the Opera web browser. It may not be distributed under any circumstances.
$Id$

Introduction

"XML names" are the names of elements and attributes in XML documents. They can be represented in a couple of different ways:

Qualified name
A qualified name is a single string that matches either of the productions NCName or QName from the Namespaces in XML specification (or the corresponding productions from the Namespaces in XML 1.1 specification.) A qualified name needs to be used together with additional namespace information.
Expanded name
An expanded name is two strings; the local part of a qualified name and a namespace URI. The term "expanded name" is commonly used in various specifications to describe such a representation of a name.
Complete name
A complete name is an extension to the expanded name that adds a third string; the prefix used in the qualified name.

Usage

The "qualified name" form is mostly only used while parsing (either while parsing the XML source or while handling attributes whose values are qualified names.) Since it doesn't contain enough information to have any real meaning, it shouldn't be used directly. In particular: one should never assume that a namespace prefix has any particular meaning unless that namespace prefix has been declared (the namespace prefixes xml and xmlns are of course exempt from this rule, they always have the same meaning.

The "expanded name" form should be used when only the meaning of the name is interesting, not how it was expressed in the XML source. This is usually the case when one parses XML.

The "complete name" form should be used when both the meaning of the name and how it was expressed in the XML source is interesting. Examples of when this is the case are when parsing documents that will be accessible from DOM (the prefix must be known in order to implement the property Node.prefix) and when parsing XSLT (literal result elements, when instantiated, will be created with the same prefix as was used in the XSLT stylesheet source.)

Classes

Four classes are used to represent expanded names and complete names: XMLExpandedName, XMLExpandedNameN, XMLCompleteName and XMLCompleteNameN. The classes XMLExpandedName and XMLCompleteName deal with null-terminated strings and can optionally own the string values while the classes XMLExpandedNameN and XMLCompleteNameN deal with unterminated strings with explicit length.

The N-versions are useful since they can be constructed from a qualified name without memory allocation or copying. To create a null-terminated version of the name one can first create an explicit length version from a qualified name and then initialize the null-terminated version from it. When constructing expanded or complete names from qualified names one of course need to resolve prefixes into namespace URIs using the namespace declarations in scope. See the XML namespaces document for more details on how to do that.