![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
OPF header error
Editing an epub2, that works fine except that epubcheck hates the OPF file.
The head of the file: Code:
<?xml version="1.0" encoding="utf-8"?> <package version="2.0" unique-identifier="BookId" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"> <metadata> This gives epubcheck errors: ERROR(RSC-005): Error while parsing file 'element "package" not allowed here; expected element "opf:package" or "package" (with xmlns="http://openebook.org/namespaces/oeb-package/1.0/")'. ERROR(RSC-005): Error while parsing file 'element "dc:identifier" not allowed here; expected the element end-tag or text'. -- then a similar error for every single line in the OPF. The rest of the OPF looks very much the same as any other, so I'm pretty sure the problem is the definitions in the headers. I have zero understanding of what these header lines do, except perhaps the unique-identifier. So I took the headers from another epub2, changing only the unique-identifier, pasted that in and now epubcheck is happy. Code:
<?xml version="1.0" encoding="utf-8"?> <package version="2.0" unique-identifier="BookId" xmlns="http://www.idpf.org/2007/opf"> <metadata xmlns:dcterms="http://purl.org/dc/terms/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/"> Why do some of the "xmlns" appear in the "package" line, others in the "metadata" tag? How can these URLS be necessary, since ebooks are readable on devices without internet connection? |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,069
Karma: 91577715
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
You should read about how XML namespaces work. Here is one tutorial: https://www.w3schools.com/xml/xml_namespaces.asp
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,759
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Make the opf namespace the default (no prefix needed) otherwise the package tag (and all its child tags) would need the opf: prefix.
change it to: xmlns="http://www.idpf.org/2007/opf" |
![]() |
![]() |
![]() |
#4 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,759
Karma: 5706256
Join Date: Nov 2009
Device: many
|
The OPF is a pure xml document.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
I am aware of that.
Doesn't help me work out which namespaces are required for epubs, which lines they should go in, or what they do. I really don't know why there isn't just an epub namespace that is implied. Calibre or anyone else can add others if they want to put their tags in the OPF. |
![]() |
![]() |
![]() |
#7 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Quote:
So I tried this: Code:
<package unique-identifier="BookId" version="2.0" xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"> <metadata> <dc:identifier id="BookId" scheme="ISBN">9781234567890</dc:identifier> ERROR(RSC-005): Error while parsing file 'attribute "scheme" not allowed here; expected attribute "ns1:scheme" or "ns2:type" (with xmlns:ns1="http://www.idpf.org/2007/opf" xmlns:ns2="http://www.w3.org/2001/XMLSchema-instance")'. I tried to add opf: <dc:identifier id="BookId" opf:scheme="ISBN"> But as soon as I did a save, the opf: disappeared, so same error. So I reverted. |
|
![]() |
![]() |
![]() |
#8 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,759
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Add this to the metadata tag itself as attributes:
xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" Then prefix the scheme attribute with opf: as it is a descendant of the metadata tag. That way attributes that only exist in the opf namespace can be used in the children of the metadata tag with the opf: prefix but all other tags will not need to be prefixed in the opf because the package tag made it the default. Here is the empty epub2 template that Sigil uses in case this helps: Code:
static const QString TEMPLATE_TEXT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<package version=\"2.0\" xmlns=\"http://www.idpf.org/2007/opf\" unique-identifier=\"BookId\">\n\n" " <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:opf=\"http://www.idpf.org/2007/opf\">\n" " <dc:identifier opf:scheme=\"UUID\" id=\"BookId\">urn:uuid:%1</dc:identifier>\n" " <dc:language>%2</dc:language>\n" " <dc:title>%3</dc:title>\n" " </metadata>\n\n" " <manifest>\n" " </manifest>\n\n" " <spine>\n" " </spine>\n\n" "</package>"; Last edited by KevinH; 12-23-2021 at 05:04 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
epub opf error | galaxyhub | Calibre | 2 | 04-05-2020 06:20 AM |
ePub3 to Mobi Error - Error(prcgen):E21027: Epub file has more than one opf file | dtsmith | Kindle Formats | 4 | 01-30-2018 11:20 AM |
Change opf filename from content.opf to title.opf | northstar7 | Sigil | 3 | 09-23-2013 12:44 PM |
Bad magic number for file header error | RedCanyoneer | Devices | 8 | 03-13-2013 11:29 AM |
error apos in opf | Fabienne78 | ePub | 2 | 10-26-2011 07:24 AM |