Monday, February 18, 2008

XML Nodetype Constants

Update, 04.03.08: It appears I was fooled by Prototype. The Node-interface/object is not available in IE.
..if (!window.Node) var Node = { };

if (!Node.ELEMENT_NODE) {
// DOM level 2 ECMAScript Language Binding
Object.extend(Node, {
ELEMENT_NO..


From reading JS-code in different places, it doesn't look like many people are aware that there are constants for the different node-types in a HTML/XML-document.

Most code I've come over tests the type like this:
if( xmlNode.nodeType == 1 )

Which is ok, if you remember that 1 corresponds with element-nodes. The Node-interface in DOM level 1 contains a property/constant for each of the nodetypes.

A list of the constants:
ELEMENT_NODE: 1
ATTRIBUTE_NODE: 2
TEXT_NODE: 3
CDATA_SECTION_NODE: 4
ENTITY_REFERENCE_NODE: 5
ENTITY_NODE: 6
PROCESSING_INSTRUCTION_NODE: 7
COMMENT_NODE: 8
DOCUMENT_NODE: 9
DOCUMENT_TYPE_NODE: 10
DOCUMENT_FRAGMENT_NODE: 11
NOTATION_NODE: 12

A more readable version to the previous test:
if( xmlNode.nodeType === Node.ELEMENT_NODE )

Monday, February 11, 2008

I'm somewhat addicted

60%How Addicted to Blogging Are You?

Tuesday, February 5, 2008

ReadableLookups: Global constants for forms/subforms

This technique is probably overkill on smaller applications. It's quite verbose compared to writing the values directly into fields/computed texts. Long living, ever changing applications may benefit using this technique though, maintainability-wise.

Basically, the technique is a shared, computed for display field that you put in all your forms. This field may contain the names of lookup-views, index of lookup-columns, replica-id's, filepaths to co-existing applications, et cetera.

Due to the nature of the readable lookups, there's no problem with inline comments in the field, or re-organizing the "constants".

Example of field

To extract a value from the field, you have to use quite a verbose syntax, but if the constant is used a lot of places, the added verbosity is worth it, as you only have to change the value one place, in the shared field.

Example of extraction of value from constants-field:

(name of shared field, SF_CONSTANTS)

If you want the Notes/Domino constants available to Javascript/etc on the web as XML, simply put the field in a form with content-type: text/xml. Add a document-node (APPLICATION_CONSTANTS in the example below), and you have access to the constants on the web as well.

The form
Example of output XML

Since the constants are in a field, the values are also available to LotusScript when working with documents.

Simple function to extract values in LS.

PS! Remember to put the field at the top of the form, so that it is available to all the other fields in the form