Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 12-22-2021, 09:09 PM   #1
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
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/">
Can anyone explain what the actual problem was?
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?
AlanHK is offline   Reply With Quote
Old 12-22-2021, 09:38 PM   #2
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
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
jhowell is offline   Reply With Quote
Advert
Old 12-22-2021, 10:45 PM   #3
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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"
KevinH is online now   Reply With Quote
Old 12-22-2021, 10:46 PM   #4
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by jhowell View Post
You should read about how XML namespaces work. Here is one tutorial: https://www.w3schools.com/xml/xml_namespaces.asp
That isn't specific to epub usages.
AlanHK is offline   Reply With Quote
Old 12-22-2021, 11:14 PM   #5
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,759
Karma: 5706256
Join Date: Nov 2009
Device: many
The OPF is a pure xml document.
KevinH is online now   Reply With Quote
Advert
Old 12-22-2021, 11:42 PM   #6
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by KevinH View Post
The OPF is a pure xml document.
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.
AlanHK is offline   Reply With Quote
Old 12-23-2021, 12:18 AM   #7
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by KevinH View Post
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"

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>
That gives an error on the BookId line:

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.
AlanHK is offline   Reply With Quote
Old 12-23-2021, 04:38 PM   #8
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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.
KevinH is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 07:51 PM.


MobileRead.com is a privately owned, operated and funded community.