How to build a PURL
How to build a PURL string from its components
Building a PURL ASCII string works from left to right, from type to
subpath.
Note: some extra type-specific normalizations are required.
To build a PURL string from its components:
-
Start a PURL string with the
schemeas a lowercase ASCII string. -
Append the
typestring to the PURL as an unencoded lowercase ASCII string. -
Append '/' to the PURL.
-
If the
namespaceis not empty:- Strip the
namespacefrom leading and trailing '/'. - Split on '/' as segments.
- Apply
type-specific normalization to each segment if needed. - UTF-8-encode each segment if needed in your programming language.
- Percent-encode each segment.
- Join the segments with '/'.
- Append this to the PURL.
- Append '/' to the PURL.
- Strip the
namefrom leading and trailing '/'. - Apply
type-specific normalization to thenameif needed. - UTF-8-encode the
nameif needed in your programming language. - Append the percent-encoded
nameto the PURL.
- Strip the
-
If the
namespaceis empty:- Apply
type-specific normalization to thenameif needed. - UTF-8-encode the
nameif needed in your programming language. - Append the percent-encoded
nameto the PURL.
- Apply
-
If the
versionis not empty:- Append '@' to the PURL.
- UTF-8-encode the
versionif needed in your programming language. - Append the percent-encoded
versionto the PURL.
-
If the
qualifiersare not empty and not composed only ofkey/valuepairs where thevalueis empty:-
Append '?' to the PURL.
-
Build a list from all
key/valuepairs:- Discard any pair where the
valueis empty. - UTF-8-encode each
valueif needed in your programming language. - If the
keyis 'checksum' and this is a list of checksums join this list with a ',' to create thisqualifiervalue. - Create a string by joining the lowercase
key, the equal '=' sign and the percent-encodedvalueto create aqualifier.
- Discard any pair where the
-
Sort this list of
qualifierstrings lexicographically. -
Join this list of
qualifierstrings with a '&' ampersand -
Append this string to the PURL.
-
-
If the
subpathis not empty and not composed only of empty, '.' and '..' segments:- Append '#' to the PURL.
- Divide the
subpathinto segments using the path delimiter of your environment (operating system, file system, etc.). - Discard empty, '.' and '..' segments.
- Percent-encode each segment.
- UTF-8-encode each segment if needed in your programming language.
- Join the segments with '/'.
- Append this to the PURL.