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
- Find the prefix attribute on the package element of the .opf file.
- 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/". - 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.
- 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-003Item "…" exists in the EPUB, but is not declared in the OPF manifest.OPF-005Invalid prefix declaration: URI for prefix "…" doesn’t exist.OPF-002The OPF file "…" was not found in the EPUB.OPF-006Invalid prefix declaration: URI "…" is not a valid URI.OPF-001There was an error when parsing the EPUB version: ….OPF-007Re-declaration of reserved prefix "…".
Sources
Message text and severity from EPUBCheck 5.4.0 (W3C, BSD-3-Clause). Explanation by EpubCC.