A while ago, I posted a 1/2 formed idea for what was probably an\novercomplicated scheme for improving how we create content using the DOM API.\nSince then, I've been refactoring some real-world code that builds content\nwith DOM, and have come up with a much simpler, more practical idea that I've\nhad success in implementing.\n\nThe problem in a nutshell is that, to build a tree or fragment in the DOM,\nit's just about impossible to arrange the code to be structured much like the\nXML being generated. Furthermore, the size of the code and the degree of\ncoupling with the DOM is outrageuos. You have to invoke a method of the\ndocument object to create each new node, you have to invoke an appendChild\nmethod of each node to add content to it, and you have to pass a namespace\nargument to each createNode call if you want it to have a namespace URI, even\nif they're all the same. Finally, the syntax for creating and appending\nattribute nodes is totally nuts, and nothing like adding child elements.\n\nOf course, you can solve all these problems with an appropriate wrapper class\nor set of wrapper classes, but we're each inventing our own wrappers to do\nthis, each solving the problems described above with varying degrees of\nsuccess.\n\nThe solution I came up with, I think is really nice, and involves using the\nnative capabilities of most languages to build nested arrays in-line along\nwith some very trivial parsing to allow the use of compact node definition\nstrings (syntax roughly similar to XPath). The inability of nested arrays to\nrepresent children of sepcific nodes is solved simply by treating any nested\narray as the set of children for the preceeding node in the array.\n\nHere's a hypothetical example (similar to some real, working code) in VB...\n\nDOMWrap.DOM.appendChild DOMWrap.createFragment( _\nArray("Invoice", Array(\n"@date=", Date, _\n"Customer", Array( _\n"@name=", CustName),\n"Body",\nInvoiceLines()))), _\n"uri:fooinc.com:invoice"\n\nIn the array, each element may be a node definition string, a node object, or\na fragment. A node definition may end with a dangling = sign, in which case,\nthe next array item supplies the text content for the node. Notice that the\ncode above has a structure much like the XML it is generating, and is vastly\nmore compact and easy to read than if it were written as discrete createNode\nand appendChild calls. Also notice that, if all the nodes being created from\nstring definitions are in the same namespace, I only have to pass a single\nnamespaceURI argument.\n\nSo - my suggestion is to create this simple wrapper in many languages (at\nleast Java, C#, VB, Perl, and Python), put it on SourceForge, and try to get\npeople to use it as a de facto standard, so no one has to reinvent this wheel\nagain.\n\nWould anyone besides me be interested in having me do that?\n\n- Steve J.