I created a small library to parse xml to javascript. Can anyone tell me if the design is correct for a library or if there is a better technique?
I wrote a small Usecase example here. You can find the code here
Edit
(function (window, undefined) {
var X2J = {
//public method
parseXml: function (xmlDocument, xpathExpression) {
//private method
var isObjectEmpty = function (obj) {};
var GetChildNode = function (domElement) {};
//...
},
//public method
getValue: function (jNode, name, index, default_value) {},
//...
};
window.X2J = X2J;
} (window));
Usage:
var x2jObj = null;
$.get('shows.xml', function (xmlDocument) {
x2jObj = X2J.parseXml(xmlDocument); //X2J.parseXml(xmlDocument, '/');
//x2jObj is called jNode
console.log('x2jObj populated', x2jObj);
console.log('To get name "One Piece (US)"', X2J.getValue(x2jObj[0].Results[0].show[1], 'name'));
});