Re: FAQ Topic - What online resources are available? (2009-01-29)



Jorge wrote:

I'm going to review one of these.

//**********************************************************

An Inconvenient API: The Theory of the DOM:

<http://video.yahoo.com/video/play?vid=111582>


Interesting history.

That video mentions a strategy for not sending javascript to unsupported browsers.

He also advocates not including the required |type| attribute of a script tag and having the server send the mime type header. This results in the document being invalid. It will work, but the validation error will appear.

In general, it is a good idea to validate the document. Developers will often complain that it doesn't work, when they've gone and used invalid HTML.

Collections:
document.anchors
...
document.stylesheets

That is a mistake. It should be: document.styleSheets.

| The earliest view of the dom was as um a collection of collections,
| and the through these collections you could get particular
| elements and modify them.

| These collections are still available in the browsers (um). They're
| not in any standard, but ah they're obsolete now. They're uh, as we'll
| see, more modern alternatives to all of these things. So these are
| pretty much irrelevant now. I recommend you not use them.

DOM 1 defined these, so they're in a standard. I don't understand why he recommends not to use these.


| Instead of using document.all, the w3c said: "Instead, we should use
| document.getElementById(id)" This has the advantage in that its
| longer and requires more typing.

LOL

| [getElementsByName] will return an Array of things which happen
| to have a name.

That's not correct. Instead, getElementsByName(name) returns a *NodeList* of *Elements* whose name matches the name argument. Except in IE < 8 which confuses ID and NAME (a common bug that most regulars are well aware of).

| Also, this particular tree [refers to diagram] is an Internet Explorer
| Tree. FIrefox will give you a different tree. Ah, and you might think
| that's uh, inconvenient, you may be right.
|
| The reason for that is uh, the w3c requires that the whitespace
| between there and there (points to nodes on html diagram) be captured
| in a text node and stuck in the tree, so, there'd be, the tree would
| be a lot hairier, because all that unnecessary whitespace would be
| trapped in the structure.

It's all good until the last sentence; the whitespace is necessary and not having it causes bugs in IE.

For example:

<div id='pre'>
<strong> hello! </strong>
</div>

If we want to see the whitespace, we can use:

document.getElementById('pre').style.whiteSpace = 'pre';

but if whitespace was dropped, as in IE, then it would not work.

All the time I have for now.

I can't recommend that.

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
.



Relevant Pages

  • Re: c++ XML processor class?
    ... If your problem is that you find DOM API cumbersome, ... traversing a tree with it and I admit this may well be my ... If you *represent* key-value pairs in XML that is perfectly ...
    (comp.text.xml)
  • Re: Reading XML stream using unmanaged c++
    ... You don't need a back pointer to implement tree structures. ... but a back pointer is a handy thing to have when using a DOM node. ... XML is metadata, but an XML document is an XML metadata structure with actual data ...
    (microsoft.public.vc.mfc)
  • tktreectrl and notify bindings
    ... I'm using the tktreectrl widget to display a DOM node tree (BTW, ... This is achieved by use of the <Expand-before> notify event. ...
    (comp.lang.tcl)
  • Re: c++ XML processor class?
    ... Do you imply xerces-c++ doesn't have a DOM parser? ... rather I don't see a easy way of traversing a tree with it and ... the key pairs I want to deal with not the whole tree structure. ...
    (comp.text.xml)
  • Re: newlines with XmlTextWriter
    ... nodes at the bottom where whitespace is significant. ... I have a feeling that if there are any newlines in the tree (or maybe any ... and it only puts its own in if there are none at all in the DOM. ... Can you give an example of the formatting you want? ...
    (microsoft.public.dotnet.xml)