Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are browsers permitted to render <li>s in any order?

Tags:

xml

xhtml

As I understand the XML spec, the significance of the order of child elements is not guaranteed. XML parsers tend to keep child elements in the same order as they occur in the XML document, but they are under no obligation to do so.

If that's so, then are browsers free to render the <li>s in an <ol> or an <ul> in a different order than they occur in XHTML? Or is it specified in the XHTML spec somewhere that order has to be preserved?

I realise that all major browsers will respect the order of my <li>s. I'm just interested in the academic question of whether or not they are technically obliged to.

like image 331
ctford Avatar asked May 27 '10 10:05

ctford


2 Answers

I think you've totally misread the XML spec there! The order of the content of an element must not be changed in the model constructed of it. (NB: the order of presentation might be a different matter, if there were specific instructions to visually reorder. But that would be weird and I don't know if current CSS can do it.) The only part of XML that is genuinely unordered is attributes; they're a true unordered map.

FWIW, the contents of an <ul> are defined to be a sequence (i.e., ordered!) of <li> elements, so browsers can't reorder when building the document tree. That is, reordering would be utterly wrong and nobody (not even the IE development team) is stupid enough to do it.

like image 111
Donal Fellows Avatar answered Nov 15 '22 06:11

Donal Fellows


According to the XHTML 1.1 Schema for list entities the contents of <ul> and <ol> is an <xs:sequence> of <li> items. Checking the XML Schema specfication it seems that <xs:sequence> operates such that "...the element information items match the particles in sequential order...". This tends to imply to me that order of such sequences is meaningful and should be retained.

like image 43
JUST MY correct OPINION Avatar answered Nov 15 '22 06:11

JUST MY correct OPINION