code: function XmlDocument(xml) {
    xml && (xml = xml.toString().trim());
  
    if (!xml)
      throw new Error("No XML to parse!");
  
    // Expose the parser to the other delegates while the parser is running
    this.parser = sax.parser(true); // strict
    addParserEvents(this.parser);
  
    // We'll use the file-scoped "delegates" var to remember what elements we're currently
    // parsing; they will push and pop off the stack as we get deeper into the XML hierarchy.
    // It's safe to use a global because JS is single-threaded.
    delegates = [this];
    
    this.parser.write(xml);
  
    // Remove the parser as it is no longer needed and should not be exposed to clients
    delete this.parser;
  }
docs: /*
  XmlDocument is the class we expose to the user; it uses the sax parser to create a hierarchy
  of XmlElements.