JSXML XML Tools

Version 1.2 Readme June 20, 2001 Copyright (c) 2000-2001 Peter Tracey


This is the first public release of JSXML. It includes REXML, JSXMLBuilder, and JSXMLIterator are packaged together in jsxml.js. rexml.js includes REXML by itself, and REXML Lite is in rexmllite.js. rexmllitenw.js is REXML Lite with all whitespace removed.

For more information and the latest release see: http://www.envy.nu/voprak/jsxml/

For comments, a list of issues, or to submit an new issue see: http://sourceforge.net/projects/jsxml/


REXML

REXML is a simple non-validating XML parser based on regular expressions. It takes a string of XML and makes it accessible programmatically. The document is broken up into a root element which may have child elements, all of which (if they are type "element") may have child elements.

On instantiation REXML exposes the property rootElement. The root element is an XML Element, all of which have these properties and methods:
Example:
function ShowXML(strXML) {
    var xmlDoc = new REXML(strXML);
    
    alert("The root element " + xmlDoc.rootElement.name + " has " xmlDoc.rootElement.childElements.length + " child elements.");
    for (var i=0; i<xmlDoc.rootElement.childElements.length; i++) {
        alert("Child element of type " + xmlDoc.rootElement.childElements[i].type);
    }
}


REXML Lite

REXML Lite is a stripped-down version of REXML. It is under 90 lines and under 2.5 kb. The type of an element is always "element." It doesn't handle comments, processing instructions, or cdata, and the text of an element is stored in the text property only, there is no getText() method and there are no text elements. It's useful for client-side XML parsing when there are only normal elements.

JSXMLBuilder

JSXMLBuilder is a tool for editing XML. It takes the XML from a REXML element and breaks it into a linear structure. This structure was chosen because it is easy to wire into a GUI. An element's position can be found through its index and level properties. index is the vertical index of the element in the document. level is the level it's nested at. So to find all of an element's child elements you'd start at the element and go down until you find an element with a level equal to or less than the starting element's level. Instead of adding an element to an element you add the element to the document and let it know the index and level where you want to add it. You'll find that the linear structure makes it much easier to program GUIs than a tree structure would.

The JSXMLBuilder object has these properties and methods: JSXMLBuilder XML Elements have these properties and methods:
JSXMLIterator

JSXMLIterator iterates through the tree structure without using recursion. It's easy to iterate tree structures with recursion, but costly. Avoiding recursion saves valuable time.

The JSXMLIterator object has these properties and methods:
Comparisons

REXML (1.2) REXML Lite (1.2) Xparse (.91) XML For Script (.22)
Size 6.5 kb 2.5 (1.9 with no whitespace) kb 8.27 kb 20 kb
Lines 150 90 390 690
Time to parse (s:ms):
20 Lines 0:010 0:010 0:030 0:020
300 Lines 0:201 0:140 1:771 1:651
700 Lines 0:411 0:371 3:124 3:643
1400 Lines 1:261 1:132 13:498 9:363
1400 Heavy Lines* 10:103 6:518 45:761 18:115
* 1 root element with attribute, sets of 1 element with one attribute, text, and no children, followed by two elements with three chilren each with text.

Licensing

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA