XmlReader-min.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.data.XmlReader = function(A, B) {
  7. A = A || {};
  8. Ext.data.XmlReader.superclass.constructor.call(this, A, B || A.fields)
  9. };
  10. Ext.extend(Ext.data.XmlReader, Ext.data.DataReader, {
  11. read : function(A) {
  12. var B = A.responseXML;
  13. if (!B) {
  14. throw {
  15. message : "XmlReader.read: XML Document not available"
  16. }
  17. }
  18. return this.readRecords(B)
  19. },
  20. readRecords : function(T) {
  21. this.xmlData = T;
  22. var N = T.documentElement || T;
  23. var I = Ext.DomQuery;
  24. var B = this.recordType, L = B.prototype.fields;
  25. var D = this.meta.id;
  26. var G = 0, E = true;
  27. if (this.meta.totalRecords) {
  28. G = I.selectNumber(this.meta.totalRecords, N, 0)
  29. }
  30. if (this.meta.success) {
  31. var K = I.selectValue(this.meta.success, N, true);
  32. E = K !== false && K !== "false"
  33. }
  34. var Q = [];
  35. var U = I.select(this.meta.record, N);
  36. for (var P = 0, R = U.length; P < R; P++) {
  37. var M = U[P];
  38. var A = {};
  39. var J = D ? I.selectValue(D, M) : undefined;
  40. for (var O = 0, H = L.length; O < H; O++) {
  41. var S = L.items[O];
  42. var F = I.selectValue(S.mapping || S.name, M,
  43. S.defaultValue);
  44. F = S.convert(F);
  45. A[S.name] = F
  46. }
  47. var C = new B(A, J);
  48. C.node = M;
  49. Q[Q.length] = C
  50. }
  51. return {
  52. success : E,
  53. records : Q,
  54. totalRecords : G || Q.length
  55. }
  56. }
  57. });