/**
 * Document extensions.
 *
 * @author Jakob Kruse <kruse@kruse-net.dk>
 * @version $Id: DocumentX.js,v 1.1 2006/03/02 20:16:59 Jakob Kruse Exp $
 */

if (typeof Document != "undefined") {
  /**
   * Convenience method for loading XML documents from a string.
   */
  Document.prototype.loadXML = function(s) {
    // parse the string to a new doc
    var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

    // remove all initial children
    while (this.hasChildNodes())
      this.removeChild(this.lastChild);

    // insert and import nodes
    for (var i = 0; i < doc2.childNodes.length; i++) {
      this.appendChild(this.importNode(doc2.childNodes[i], true));
    }
  };

  /**
   * Convenience accessor for string representation of XML document.
   */
  Document.prototype.__defineGetter__("xml", function () {
    return (new XMLSerializer()).serializeToString(this);
  });
}

// EOF