Skip to content
EPUBCheck · Package document (OPF)

EPUBCheck OPF-004: malformed prefix attribute

Updated:

EPUBCheck OPF-004 is a warning message: “Invalid prefix declaration: leading or trailing whitespace is not allowed.” The prefix attribute on the package element is not written in the syntax EPUB requires. That attribute maps short prefixes (such as ibooks) to vocabulary URIs, and EPUBCheck reports each kind of syntax mistake with its own variant of OPF-004.

The official message

Invalid prefix declaration: leading or trailing whitespace is not allowed.

Default severity
Warning. The EPUB is still valid, but something is likely to cause problems in some reading apps. EPUBCheck exits with 0 unless you pass --failonwarnings.
EPUBCheck version
5.4.0

Typical causes

  • OPF-004: spaces or line breaks at the start or end of the attribute value; OPF-004a: an empty prefix, a colon with no name before it.
  • OPF-004b: a prefix name that is not a valid XML name (NCName), for example one starting with a digit or containing a slash; OPF-004c: a space between the name and its colon, as in "ibooks : http://…".
  • OPF-004d: no space between the colon and the URI, as in "ibooks:http://…"; OPF-004e: a tab, line break or other illegal whitespace between the prefix and the URI.
  • OPF-004f: mappings separated by something other than plain whitespace, or run together.

How to fix it

  1. Find the prefix attribute on the package element of the .opf file.
  2. Write each mapping as the prefix name, a colon, one space and the vocabulary URI, and separate mappings with whitespace, for example prefix="ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/ foaf: http://xmlns.com/foaf/spec/".
  3. Remove whitespace at the start and end of the value, give every mapping a name that starts with a letter (letters, digits, hyphens and underscores only), and put the colon right after the name.
  4. Reserved prefixes such as dcterms, rendition and schema need no declaration, so you can often delete the attribute entirely if it only maps those.

When it's not this

If the syntax is right but a prefix has no URI or an invalid one, that is OPF-005 or OPF-006.

Also reported as

  • OPF-004a (error): Invalid prefix declaration: found empty prefix.
  • OPF-004b (error): Invalid prefix "%1$s": must be a valid non-colonized name (aka "NCName").
  • OPF-004c (error): Invalid prefix declaration: prefix "%1$s" must be immediately followed by a colon character (":").
  • OPF-004d (error): Invalid prefix declaration: prefix "%1$s" must be separated by its URI with a space.
  • OPF-004e (warning): Invalid prefix declaration: found illegal whitespace between prefix and URI.
  • OPF-004f (warning): Invalid prefix declaration: found illegal whitespace between prefix mappings.

Terms used here

Other OPF messages

  • OPF-003 Item "…" exists in the EPUB, but is not declared in the OPF manifest.
  • OPF-005 Invalid prefix declaration: URI for prefix "…" doesn’t exist.
  • OPF-002 The OPF file "…" was not found in the EPUB.
  • OPF-006 Invalid prefix declaration: URI "…" is not a valid URI.
  • OPF-001 There was an error when parsing the EPUB version: ….
  • OPF-007 Re-declaration of reserved prefix "…".

Sources

Message text and severity from EPUBCheck 5.4.0 (W3C, BSD-3-Clause). Explanation by EpubCC.

FAQ

What does EPUBCheck OPF-004 mean?

EPUBCheck OPF-004 is a warning message: “Invalid prefix declaration: leading or trailing whitespace is not allowed.” The prefix attribute on the package element is not written in the syntax EPUB requires. That attribute maps short prefixes (such as ibooks) to vocabulary URIs, and EPUBCheck reports each kind of syntax mistake with its own variant of OPF-004.

Is OPF-004 an error?

OPF-004 is reported as warning by default. The EPUB is still valid, but something is likely to cause problems in some reading apps. EPUBCheck exits with 0 unless you pass --failonwarnings.