From COLLADA Public Wiki
Revision as of 01:14, 1 June 2007 by Elf (talk | contribs) (chg catg name)
Jump to navigation Jump to search

URIs are used extensively in COLLADA documents to reference other COLLADA elements or external resources such as texture files, shader source code, and so on. A URI must be formatted properly for the application to find the resource the URI identifies. This article describes how to use URIs in COLLADA.


The COLLADA schema uses the xs:anyURI type to represent URIs. This type allows relative URI references in addition to URIs, so you can use either in a COLLADA document.

Some examples of URI usage in COLLADA include

  • The target attribute of <instance_material> elements
  • The url attribute on <instance_geometry>, <instance_node>, and <instance_effect> elements
  • The <image>/<init_from> element

For URIs that reference COLLADA elements (such as the url attribute on the <instance_geometry> element), the fragment portion identifies the element by its id attribute. An example of this:

<instance_geometry url="file:///models/car.dae#carGeometry" />

This <instance_geometry> references the <geometry> element whose id is carGeometry in the document file:///models/car.dae.

The following example uses a relative reference, which must be resolved to a URI before the application can obtain the referenced <geometry> element:

<instance_geometry url="../car.dae#carGeometry" />

Base URIs in a COLLADA document

To resolve relative URI references, a base URI is needed. In COLLADA, the base URI can be specified in the root <COLLADA> element:

<COLLADA xmlns="" version="1.4.1"

If the xml:base attribute isn't specified, then the base URI is the document's URI. For example, if the document's URI is file:///car.dae, then COLLADA uses that as the base URI to resolve any relative references in the document.

Paths versus URIs

An ordinary Windows or Linux file path is not a valid URI. A file-scheme URI (see [1]) represents a file on the local machine. File paths need to be converted to file-scheme URIs before they can be used properly by COLLADA applications. If the base URI's scheme is file (which is usually the case), then you can use a relative reference to the file instead of specifying a full file-scheme URI. When the reference is resolved by the application, it becomes a valid file-scheme URI.

The following examples specify a file via a relative URI reference in COLLADA. These examples assume that the base URI's scheme is file; otherwise, the reference won't resolve correctly. You might use these examples in the <image>/<init_from> element to refer to an image file on disk.

Example Description File Path URI Reference
Windows absolute path
Windows relative path
Linux absolute path
Linux relative path
UNC path

In particular, note that "\" characters convert to "/", and that Windows-style "C:" specifiers must be prepended with "/" to become proper URI references.

So, in a COLLADA document you could write


Suppose the base URI is file:///C:/models/maya/car.dae. An application will resolve the relative reference against the base URI to get file:///C:/models/folder/image.tga, which is a valid file-scheme URI.

As the last example in the table shows, an exception is made for Windows UNC paths. In theory, you could convert the UNC file path \\remoteMachine\folder\image.tga to the relative reference //remoteMachine/folder/image.tga. The spec calls this a network-path reference (as described here). The authority is remoteMachine and the path is /folder/image.tga. Assuming that the base URI is file:///C:/models/maya/car.dae, this resolves to the URI file://remoteMachine/folder/image.tga.

However, many XML parsers can't work correctly with such URIs. One example is libxml, which the COLLADA DOM uses to load COLLADA documents. Instead of specifying the UNC path as a URI reference, it's better to use a file-scheme URI as shown in the table, with which most XML libraries can work correctly.

See also