A FictionBook file is one XML document whose root, FictionBook, holds in
order: any number of stylesheet elements, one description, one
body with the text, optionally a second body for
the notes (the repository’s schema; the published 2.0, 2.1 and 2.2 schemas allow any number of bodies with any name,
see the versions), and any number of binary
elements. This page covers the description, the book’s metadata. Element
names and occurrences are those of the FictionBook 2 XML schema
(FictionBook.xsd), whose namespace is
http://www.gribuser.ru/xml/fictionbook/2.0; links use XLink, namespace
http://www.w3.org/1999/xlink, usually with the prefix l: or
xlink:.
The file
- The encoding is given in the XML declaration. UTF-8 and Windows-1251 (Cyrillic) are the most common; readers must honour the declaration. A declaration of a single-byte encoding over bytes that are, throughout, valid UTF-8 is a wrong declaration (the text shows as garbage); the explorer reports it.
- The extension is
.fb2. Files are often zipped one per archive as.fb2.zipor.fbz, which readers open directly; the explorer opens both as a ZIP archive whose.fb2member opens as a FictionBook. - There is no binary header: the file starts with the XML declaration, sometimes
after a UTF-8 byte order mark, then
<FictionBook.
description
| Child | Number | Content |
|---|---|---|
title-info | 1 | The book itself: see title-info. |
src-title-info | 0–1 | The same fields for the original, when the book is a translation. |
document-info | 1 | The FB2 file as a document: who made it, when, its ID and version. See document-info. |
publish-info | 0–1 | The printed edition the text came from. See publish-info. |
custom-info | Any | Free text, with a required info-type attribute naming what it is. |
output | 0–2 | Rules for making paid and free copies; in both schema files (see the versions). See output. |
title-info and src-title-info
| Child | Number | Content |
|---|---|---|
genre | 1 or more | A genre code. Attribute match: how well the genre fits, read as a percentage, default 100. Its type is xs:integer with no limits, so any whole number is valid. |
author | 1 or more | An author. |
book-title | 1 | The title. |
annotation | 0–1 | A blurb, in the same block elements as a section (paragraphs, poems, quotes, tables). |
keywords | 0–1 | Keywords, separated by commas. |
date | 0–1 | When the work was written: see dates. |
coverpage | 0–1 | One or more image elements pointing to cover images in binary elements. |
lang | 1 | The language of the book, such as ru or en. |
src-lang | 0–1 | The language of the original, for a translation. |
translator | Any | A translator, with the same content as author. |
sequence | Any | A series the book belongs to: see sequence. |
The elements must appear in this order. Text elements (book-title,
keywords and the like) may carry xml:lang.
Dates
A date element holds a date as people would read it, in any form, and
optionally a machine-readable value attribute in ISO form
(YYYY-MM-DD): <date value="1895-01-01">1895</date>.
It may carry xml:lang. The year of
publish-info is a plain year.
sequence
An empty element (or one holding nested sequence elements, for a
sub-series) with attributes name (required, the series name),
number (optional, the book’s number in it: xs:integer) and
xml:lang: <sequence name="Discworld" number="3"/>.
document-info
| Child | Number | Content |
|---|---|---|
author | 1 or more | Who made the FB2 file (scanned, proofread, marked up). |
program-used | 0–1 | The programs used. |
date | 1 | When the file was made. |
src-url | Any | Where the source text came from. |
src-ocr | 0–1 | Who scanned and recognised the original. |
id | 1 | A unique ID for this document, often a GUID; libraries use it to spot duplicates. |
version | 1 | The version of the file, a decimal number such as 1.0 or 1.1, raised when it is corrected. |
history | 0–1 | The change history, as annotation-like block content. |
publisher | Any | The owner of the electronic edition, as an author structure. |
publish-info
| Child | Number | Content |
|---|---|---|
book-name | 0–1 | The title of the printed book. |
publisher | 0–1 | Its publisher, as text. |
city | 0–1 | The city of publication. |
year | 0–1 | The year of publication. |
isbn | 0–1 | The ISBN. |
sequence | Any | The publisher’s series. |
output
Instructions for a shop or library that makes copies of the book for readers, for example a free extract and a paid full copy. At most two.
| Element | Attributes | Content |
|---|---|---|
output | mode (required): free or paid. include-all (required): require, allow or deny. price, currency. | part and output-document-class elements. |
part | xlink:href (required), xlink:type, include (required): require, allow or deny | Empty: whether a part of the book, by ID, goes into the copy. |
output-document-class | name (required), create (require, allow or deny), price | part elements: settings for one kind of output document. |
stylesheet
Before the description, stylesheet elements may hold style rules, with
a required type attribute such as text/css. They style the
named style elements of the text. The FictionBook description (fictionbook.org) says the only way to influence rendering is by specifying
styles for paragraphs and for strings of characters, and recommends one text/css stylesheet if any styles are used; the schema’s
carriers are the style element (name) and the style attribute (xs:string) of paragraphs, cells and tables. What programs do with it differs, see
Divergence from spec.
FictionNotes.xsd: reader notes and bookmarks
The same repository holds a fifth schema, FictionNotes.xsd, which is not part of a book: it is a
separate XML format for what a reader adds to one, bookmarks, notes and highlighted selections, kept in a file of its own or
exchanged with a server. Its root is FictionBookMarkup in the namespace
http://www.gribuser.ru/xml/fictionbook/2.0/markup (not the book’s), and it imports the book’s schema for the
paragraph, picture, poem, citation and table types. The explorer does not open it as such: a file with that root opens as plain XML.
What the schema (read in full, as one raw file) says:
| Element or attribute | Content |
|---|---|
FictionBookMarkup | Any number of Selection. Optional lock-id (a UUID): used when synchronising with a server so several clients of one user do not collide; useless offline. |
Selection | Any number of Note, then at most one Extract. Required attributes: id (a UUID), selection (an XPointer range into the book: fb2#xpointer(point(/1/2/…, where /1/2/ is /FictionBook/body), art-id (the book’s document-info/id), group, last-update (xs:dateTime). Optional: class (an XML name of 1 to 30 characters, extending group), title (1 to 100 characters), percent (0 to 100: how far through the book it is; a bookmark of group 0 at 100 means “finished reading”). |
group | 0 to 9: 0 the current position, 1 a bookmark, 2 an important bookmark, 3 a note, 4 an important note, 5 a selection, 6 an important selection, 7 and 8 set by the application, 9 other. |
Note | The margin note: p and empty-line only, to be treated as plain text. |
Extract | The part of the book the selection was taken from (p, image, poem, subtitle, cite, empty-line, table), so a bookmark works without the original file and can be found in a newer version. Required original-location (an XPointer); optional selection-text (plain text) and selection (an xpointer(point(here()/…)/range-to(…)) pattern). |
FictionBook 2.0, 2.1 and 2.2: the published schemas
All the schemas below use the namespace http://www.gribuser.ru/xml/fictionbook/2.0 and none states its version inside the file, so a file
cannot say which it follows. The author, Dmitry Gribov, published a FictionBook.xsd for each of 2.0, 2.1 and 2.2 at
www.gribuser.ru/xml/fictionbook/2.0/xsd/, 2.1/xsd/ and 2.2/xsd/ (read from the Internet Archive’s copies; the page
gribuser.ru/xml/fictionbook/index.html of 2022 links the 2.0 file). The gribuser/fb2 repository on GitHub holds a fourth, later one, and
an older copy of it (a gist) is the 2.1 schema without valign. The four were compared whole, with white space and documentation ignored.
2.0 to 2.1
| Where | 2.0 | 2.1 |
|---|---|---|
description | only title-info, document-info, publish-info, custom-info | adds src-title-info (the book’s original) and output (up to two, the paid and free copies, with part and output-document-class) |
home-page, email (of an author) | at most one of each | any number of each |
text-author | plain text | a paragraph (inline markup) |
cite, annotation | p, poem, empty-line (and cite in annotations) | also subtitle and table |
| inline elements | strong, emphasis, style, a, image | also strikethrough, sub, sup, code; an inline image has only href, type, alt |
image | no title or id | block images take title and id |
table, tr | rows hold td only (paragraph content); no style or id on the table | rows hold th and td; style and id on the table; cells take id, style, colspan, rowspan, align (and valign in the final 2.1 file) |
2.1 to 2.2 to the repository’s file
| Where | 2.1 | 2.2 | Repository’s file |
|---|---|---|---|
document-info | no publisher | publisher (an author structure, any number) after history | as 2.2 |
author, translator (and a document publisher) | no id | an optional id as the last child | as 2.2 |
lang, src-lang | XML Schema xs:language | xs:string (any text) | as 2.2 |
| the bodies | any number of body, each with a free name | as 2.1 | one main body, then at most one notes body whose name may only be “notes” |
poem | one or more stanza | as 2.1 | one or more of subtitle and stanza, in any order |
| genre list | 109 codes | the same 109 | 186 codes (six of the 109 are gone), see genres |
The 2.0 schema has its own list of 372 genre codes (genres page). The output element is in 2.1, 2.2 and the repository’s file, and not in 2.0.
The repository’s file names no version; the Russian Wikipedia article on FictionBook gives 2.21 (16 January 2008) as the latest, and no schema file read says so. Kondratovich’s book
(“Создание электронных книг в формате FictionBook 2.1”, section “Версии 2.2 и 2.21”, read at e-reading.club, saved in research/fb2/) says what the two versions are: 2.2
(February 2007) added id to authorType and publisher to document-info; in January 2008 the genre list changed (sci_business removed and a section of twelve
business genres added: job_hunting, management, marketing, banking, stock, accounting, global_economy, economics,
industries, org_behavior, personal_finance, real_estate), and subtitles in poems became possible. The repository’s file has exactly those: it lacks
sci_business, has all twelve codes, and lets a poem hold a subtitle. So the repository’s file is the 2.21 schema (the book gives the changes, not the number on the file), with one
addition the book does not mention, the rule that the notes body is named notes. The schema that FictionBook Editor ships (FBE/FictionBook.xsd in evpobr/fictionbookeditor) was compared line by line
with both: it equals the published 2.2 except that a poem may hold subtitle beside stanza, and it equals the repository’s file except that the repository also
requires the notes body to be named notes. The file carries no version text.
The author’s description of what 2.1 added is the fictionbook.org wiki page “Нововведения в FictionBook 2.1 по сравнению с 2.0” (Internet Archive copy of 22 March 2016). It lists seven changes:
the optional src-title-info for translated books (the same structure as title-info); the four new inline styles sub, sup, code and
strikethrough; text-author becoming a styled paragraph; a scheme in the header for controlling the conversion of paid documents (the output element); a new genre list; simple tables
(with the cell attributes style, id, align, valign, colspan and rowspan); and title and id on block images (inline images and
cover images still have neither). Each of the seven is in the 2.0-to-2.1 table above, found in the schemas independently; the schemas add further changes the page does not list
(several home-page and email, subtitle and table inside cite and annotation). The wiki’s page for 2.2 is the 2.2 schema itself, which it says is the one in use at
the bookshop LitRes, and it names no change from 2.1. The wiki’s per-element pages (for example “Элемент stylesheet”, 2005) hold only the schema fragment and examples; its page for output is marked unfinished.
The sources are saved as research/fb2/fictionbook.org-*.html; the wiki’s text is under the GNU Free Documentation License.
A file is valid under one, several or none of the four, and the explorer’s Published schemas field says which, by running each schema over the file
(the same engine as the schema check, agreeing with xmllint --schema on every file tried). A file that one of the older schemas accepts is not reported as having problems because the newest rules would reject it.