Note how I didn't check that the node is an actual <form>, simply that it's an ELEMENT_NODE (nodeType == 1). This allows extracting, for instance, only part of a form, like a <fieldset>, or pretty much any container that holds form elements.