View Full Version : Validation Errors


luthar28
08-09-2010, 04:35 PM
Hi there,

I ran my epub through the 1.0.5 validation tool. Looks like I'm getting errors based on my HTML.

I received two types of reoccuring errors.

The first:

ERROR: c:\test.epub/nexus_ascension_split_019.html(8): bad value for attribute "id"

Second:

ERROR: c:\test.epub/nexus_ascension_split_018.html(53): element "br" from namespace "http://www.w3.org/1999/xhtml" not allowed in this context

Any ideas?

Toxaris
08-09-2010, 05:43 PM
The second is easy. <br> is not allowed in XHTML. Change it in <br />.

De first is probably a wrong value for id (look at line number) in reference to the nxc or opf file.

luthar28
08-09-2010, 07:52 PM
The second is easy. <br> is not allowed in XHTML. Change it in <br />.

De first is probably a wrong value for id (look at line number) in reference to the nxc or opf file.

I like the easy ones. Fixed the <br> to <br />

The second was that I had 'id' start with a digit...so I just changed that. Easy.

I'm still getting problems with H3 and <a> tags. This is what I have:

<a class="Chapter" id="c1_1"><h3>5 DAYS LEFT</H3></a>

After I import it into Calibre, change it to an E-pub, then open it in Sigil, it <h3 class="calibre12" id="calibre_toc_8"><a class="calibre7" id="c1_1">EA</a></h3>

I can see how to change the <a> tag (remove the class, I suppose...change it to a straight div) but what's wrong with the h3 tag?

But it's even weird how I have it <a><h3></h3></a> and calibre turns it into <h3><a></a></h3>

Lexicon
08-09-2010, 08:10 PM
<h3> is a block tag and <a> is an inline one. I'm not sure it is valid to put a block element inside an inline element, but even if it is I'm not surprised a parser/writer would reverse the two. You couldn't really call it a bug either as the resulting code is functionally identical.

luthar28
08-09-2010, 08:51 PM
<h3> is a block tag and <a> is an inline one. I'm not sure it is valid to put a block element inside an inline element, but even if it is I'm not surprised a parser/writer would reverse the two. You couldn't really call it a bug either as the resulting code is functionally identical.

So how should it be coded? What I'm trying to do is set hyperlinks to target Chapter headers.

Thus: <a class="Chapter" id="c0_1"><h3>THE TWINS</h3></A>

The class chapter does a page break before. Every error is based on these two (<a> and <h3>)

charleski
08-09-2010, 10:39 PM
Very easy, the answer is:
<h3><a id="c0_1" />THE TWINS</h3>
Calibre and Sigil were trying to fix it for you.

An epub's xhtml body can only contain block elements (div, p, blockquote, ul, , h1, etc). Text and anchors must be contained in a block element of some sort. Since your anchor here is merely acting as a target for an external reference, there's no need to wrap it around the text either, it just needs to sit next to it.

luthar28
08-10-2010, 12:05 AM
Very easy, the answer is:
<h3><a id="c0_1" />THE TWINS</h3>
Calibre and Sigil were trying to fix it for you.

An epub's xhtml body can only contain block elements (div, p, blockquote, ul, , h1, etc). Text and anchors must be contained in a block element of some sort. Since your anchor here is merely acting as a target for an external reference, there's no need to wrap it around the text either, it just needs to sit next to it.

Oh, geez, that was easy too :)

Last question (honestly, it is...I'm down to my last error). I'm getting this error: element 'img' from namespace not allowed in this context.

The code in question (from the source) is

<img alt="Nexus Ascension" class="backcover" src="back_cover.jpg">

The css for class is: img.backcover {width:100px;max-width:40%; margin-top:3em;}

I have another img earlier (using the exact same naming conventions) and it passes okay.

Toxaris
08-10-2010, 05:23 AM
You should have guessed by now....

Replace <img ....> by <img ... />. Within XHTML you need an ending tag, like <p></p>. Since some tags don't have an ending (like <BR> and <IMG>), you can usually solve it by replacing > by />. Another 'famous' one is <HR>.

I also found that epubcheck doesn't like it when you use upper and lowercase mixed. So for example <P>...</p>. So make sure you either do only upper or lowercase to avoid confusion.

Valloric
08-10-2010, 08:30 AM
I also found that epubcheck doesn't like it when you use upper and lowercase mixed. So for example <P>...</p>. So make sure you either do only upper or lowercase to avoid confusion.

XHTML is case-sensitive. <p> and <P> are not the same tag. Epubcheck is correct in pointing out a problem here.

luthar28
08-10-2010, 10:44 AM
Thanks to everyone's reply.

This has helped a ton and my document has finally been validated.

luthar28
08-10-2010, 12:35 PM
Okay, I thought I had it all figured out. First book has been validated. Then applied those coding changes to second. I am now experiencing the following error: element a from namespace not allowed in this context.

The code is as follows: <h2><a class="chapter" id="c1_1">MK#1: MAJOR KARNAGE</a></h2><h3>CHAPTER ONE</h3>

When I open it in sigil, it has changed it to:

<p><a class="chapter" id="c1_1">MK#1: MAJOR KARNAGE</a></p>

<h3 class="calibre4" id="calibre_toc_15">CHAPTER ONE</h3>

So it has stripped out the h2 and replaced it with <p>.

Any ideas?

Jellby
08-10-2010, 12:56 PM
Try with:

<h2 id="c1_1">MK#1: MAJOR KARNAGE</h2><h3>CHAPTER ONE</h3>

(there's usually no need to use <a>)

But surely the class="calibre4" id="calibre_toc_15" bit was introduced by calibre, not Sigil?

luthar28
08-10-2010, 01:08 PM
Try with:

<h2 id="c1_1">MK#1: MAJOR KARNAGE</h2><h3>CHAPTER ONE</h3>

(there's usually no need to use <a>)

But surely the class="calibre4" id="calibre_toc_15" bit was introduced by calibre, not Sigil?

This worked perfectly -- thanks a million. Works great by taking out the <a> tag...though I wonder why the hell it worked for the proceeding book (exact same coding) but not this one?

Either way, this makes life way easier for future books by taking out that A tag.

Toxaris
08-10-2010, 01:24 PM
XHTML is case-sensitive. <p> and <P> are not the same tag. Epubcheck is correct in pointing out a problem here.

That explains it then. Never knew that, sounds silly. Oh well, easily enough avoided.