function DataSet(sourceName, data) {
	this.initialize(sourceName, data);
}

DataSet.prototype = {
	initialize: function(sourceName, data) {
		this.sourceName = sourceName;
		this.data = data;
		this.domParser = new DOMParser();
	},
	
	getSourceName: function() {
		return this.sourceName;
	},
	
	getData: function() {
		return this.data;
	},
	
	getText: function() {
		return $(this.data).toXML();
	},
	
	grep: function(xpath) {
		var match;
		if(this.data != undefined || this.data != null ) {
			match = $(this.data).find(xpath);
		}
		
		var xmlStr = "<?xml version='1.0' encoding='UTF-8'?>\n<grep>\n" + match.toXML() + "\n</grep>";
		var xml = this.domParser.parseFromString(xmlStr, "text/xml");
		var dSet = new DataSet("grep",xml);
		
		return dSet;
	}
	
	
}

///////////////////////////////////////////////// Extention
jQuery.fn.toXML = function ()
{
  var toXML = function(node)
  {
    var out = '';
    var attributes = '';
    var content = '';
    out += '<' + node.nodeName;
    if (node.childNodes)
    {
      for (var i = 0; i < node.childNodes.length; i++)
      {
        switch(node.childNodes[i].nodeType)
        {
          case 1:     // ELEMENT_NODE
            content += toXML(node.childNodes[i]);
            break;
          case 2:     // ATTRIBUTE_NODE
            attributes += ' ' + node.childNodes[i].nodeName  + '="'
                              + node.childNodes[i].nodeValue + '"';
            break;
          case 3:     // TEXT_NODE
          case 4:     // CDATA_SECTION_NODE
          case 5:     // ENTITY_REFERENCE_NODE
          case 6:     // ENTITY_NODE
          case 7:     // PROCESSING_INSTRUCTION_NODE
          case 8:     // COMMENT_NODE
          case 9:     // DOCUMENT_NODE
          case 10:    // DOCUMENT_TYPE_NODE
          case 11:    // DOCUMENT_FRAGMENT_NODE
          case 12:    // NOTATION_NODE
            content += node.childNodes[i].nodeValue;
            break;
        }
      }
    }
    out += attributes;
    if (content.length > 0)
    {
      out += '>' + content;
      out += '</' + node.tagName + '>';
    }
    else
    {
      out += '/>';
    }
    return out;
  }
  var out = '';
  if (this.length > 0) {
    if (typeof XMLSerializer == 'function' ||
        typeof XMLSerializer == 'object')
    {
      var xs = new XMLSerializer();
      this.each(function() { out += xs.serializeToString(this); });
    }
    else if (this[0].xml !== undefined)
    {
      this.each(function() { out += this.xml; });
    }
    else
    {
      if (this.length > 0)
      {
        this.each( function() { out += toXML(this); } );
      }
    }
  }
  return out;
};

