Skip to content

Commit

Permalink
removed simple-inheritance as necessary dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
derderderist committed Jun 8, 2011
1 parent 455e88a commit 41aecbe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 94 deletions.
1 change: 0 additions & 1 deletion README.markdown
Expand Up @@ -10,7 +10,6 @@ This library converts XML into a customizable data object. The data object conta
XMLtoJSON requires:

* jQuery (> 1.5)
* John's Resig Simple-Inheritance


## Usage
Expand Down
2 changes: 1 addition & 1 deletion example/dependencies/application.js
Expand Up @@ -18,7 +18,7 @@ $(document).ready(function(){
}
else{
$('#result').attr('value', js_beautify(JSON.stringify(data.json))).show();
$('#time').html('Result (' + data.duration + ')').show();
$('#time').html('Result for data.json (' + data.duration + ')').show();
$('#time, #result').appendTo($(this).parent());
return false;
}
Expand Down
63 changes: 0 additions & 63 deletions example/dependencies/simple-inheritance.js

This file was deleted.

1 change: 0 additions & 1 deletion example/index.html
Expand Up @@ -9,7 +9,6 @@
<script language="javascript" type="text/javascript" src="dependencies/json2.js"></script>
<script language="javascript" type="text/javascript" src="dependencies/beautify.js"></script>
<!-- /Render and style JSON/XML -->
<script language="javascript" type="text/javascript" src="dependencies/simple-inheritance.js"></script>
<script language="javascript" type="text/javascript" src="../lib/jquery.xmltojson.min.js"></script>
<script language="javascript" type="text/javascript" src="dependencies/application.js"></script>

Expand Down
56 changes: 29 additions & 27 deletions lib/jquery.xmltojson.js
Expand Up @@ -3,7 +3,6 @@
* @version 0.1
* @author Sebastian Kranz
* requires jQuery
* requires John's Resig Simple-Inheritance
*/

/**
Expand All @@ -26,11 +25,11 @@
* log: Enable or disable output on console for errors and converting problems
*/

var XMLtoJSON = Class.extend({

// Initialize JSON conversion
init: function(options){
var XMLtoJSON = function(options){

// Define Initialization
this.init = function(){

this.xml = false,
this.document = false;
this.json = {};
Expand Down Expand Up @@ -71,13 +70,13 @@ var XMLtoJSON = Class.extend({
// Modify JSON
this.modifyJSON();
}

// Time taken
this.duration = new Date() - this.duration + ' ms';
},
}

// Get XML as text from a external url
receiveXML: function(){
this.receiveXML = function(){
var url = this.options.url,
response;
$.ajax({
Expand All @@ -97,10 +96,10 @@ var XMLtoJSON = Class.extend({
this.throwError('Cannot receive XML from ' + this.options.url);
if(this.options.fallback != null) this.options.fallback({message : 'Cannot receive XML from ' + this.options.url, code : 404});
}
},
}

// Parse XML
parseXML: function(){
this.parseXML = function(){
this.xml = this.xml.replace(/^[\s\n\r\t]*[<][\?][xml][^<^>]*[\?][>]/, '');
if(window.ActiveXObject){
this.document = new ActiveXObject('Microsoft.XMLDOM');
Expand All @@ -112,11 +111,11 @@ var XMLtoJSON = Class.extend({
this.document = this.document.parseFromString(this.xml, 'application/xml');
}
if(!this.xml || !this.document) this.throwError('Cannot parse XML');
},
}

// Convert XML to JSON (inner closure, recursive)
// Increase performance by replace jQuery.each with native Javascript for-loop (should be 2-3 times faster, depeding von the Document size)
convertXML: function(){
this.convertXML = function(){
var _this = this;
(function evaluate(node, obj, options, ns) {

Expand Down Expand Up @@ -221,10 +220,10 @@ var XMLtoJSON = Class.extend({
}

})(this.document, this.json, this.options, {}); // Execute
},
}

// Modify JSON
modifyJSON : function(){
this.modifyJSON = function(){
var _this = this,
attributeIdentifier = this.options.attributeIdentifier;
$.each(this.options.modify, function(url, modified){
Expand Down Expand Up @@ -273,10 +272,10 @@ var XMLtoJSON = Class.extend({
}
}
});
},
}

// Create a all parts of a non existing node tree
createNodes : function(string){
this.createNodes = function(string){
var _this = this;
var node = this.get(string, false);
if(node) return;
Expand All @@ -292,10 +291,10 @@ var XMLtoJSON = Class.extend({
if(!part) eval('_this.json.' + partUrl + '={}');
checkNode(url, index+1);
})(string, 0);
},
}

// Get JSON by a full identifiable String splitted by '.'
get : function(path, log){
this.get = function(path, log){
var array = '',
root = null,
log = (log == false) ? false : true;
Expand All @@ -315,10 +314,10 @@ var XMLtoJSON = Class.extend({
if(log == true) this.throwError('Invalid path ' + path);
}
return (root) ? root : (log == true ? this.throwError('Could not access ' + path) : null);
},
}

// Find each JSON element by a given String splitted by '.' and additional conditions
find : function(path, condition){
this.find = function(path, condition){
var _this = this,
parts = [];
// Get children from path
Expand Down Expand Up @@ -457,10 +456,10 @@ var XMLtoJSON = Class.extend({
}
}
return (!parts) ? [] : parts;
},
}

// Remove JSON by a given String splitted by '.'
remove : function(string){
this.remove = function(string){
if(this.get(string)){
eval('delete this.json.' + string);
if(string.match(/\[*.\]$/)){
Expand All @@ -472,10 +471,10 @@ var XMLtoJSON = Class.extend({
eval('_this.json.' + string.replace(/\[*.\]$/, '') + ' = filterNull');
}
}
},
}

// Detect type for string values of true, false, integer and null
detectTypes : function(string){
this.detectTypes = function(string){
if(string.match(/^true$/i)){
return true
}
Expand All @@ -491,10 +490,10 @@ var XMLtoJSON = Class.extend({
else{
return string;
}
},
}

// Log specific error message
throwError: function(msg){
this.throwError = function(msg){
if(this.options.log){
if(!window.console){
// Add log method to window.console
Expand All @@ -505,5 +504,8 @@ var XMLtoJSON = Class.extend({
console.log(msg);
}
}

// Initialize
this.init();

});
};

0 comments on commit 41aecbe

Please sign in to comment.