|
A c t i o n f o r L i b r a r i e s
— D e c e m b e r 2 0 0 2
The Internet ConnectionBy Michael Sauers
Nesting lists in XHTML For example, in HTML the markup for a nested list would look similar to this:
1. <ul> Although this markup appears as though it would be valid XHTML, when run through a validator it points to the nested <ul> and gives you the following error: Error: element "ul" not allowed here; assuming missing "li" start-tag Translated into English, you're being told that the nested <ul> is in the wrong place. You're probably wondering where should it be located instead. Upon a closer reading of the XHTML document type definition (DTD), the validator provides the following: <!ELEMENT ul (li)+> This means that a <ul> code can only contain an <li>. In the above example, we have a <ul> contained within another <ul> code, rendering the markup invalid. However, looking at the rules for <li> we find: <!ELEMENT li %Flow;> There is no restriction on what can be contained within an <li>. Therefore an <li> can contain a <ul>. So, to solve our coding problem we need to nest the <ul> within an <li>, waiting to close the primary list only after the secondary list is closed. To accomplish this we must move the </li> from line three to the end of line seven. Here is our revised markup, now valid in XHTML.
1. <ul> Next Article | Previous Article | Table of Contents | BCR Publications Comments to:
shoffhin@bcr.org |