parser.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //>>built
  2. define("dojox/xml/parser",["dojo/_base/kernel","dojo/_base/lang","dojo/_base/array","dojo/_base/window","dojo/_base/sniff"],function(_1){
  3. _1.getObject("xml.parser",true,dojox);
  4. dojox.xml.parser.parse=function(_2,_3){
  5. var _4=_1.doc;
  6. var _5;
  7. _3=_3||"text/xml";
  8. if(_2&&_1.trim(_2)&&"DOMParser" in _1.global){
  9. var _6=new DOMParser();
  10. _5=_6.parseFromString(_2,_3);
  11. var de=_5.documentElement;
  12. var _7="http://www.mozilla.org/newlayout/xml/parsererror.xml";
  13. if(de.nodeName=="parsererror"&&de.namespaceURI==_7){
  14. var _8=de.getElementsByTagNameNS(_7,"sourcetext")[0];
  15. if(_8){
  16. _8=_8.firstChild.data;
  17. }
  18. throw new Error("Error parsing text "+de.firstChild.data+" \n"+_8);
  19. }
  20. return _5;
  21. }else{
  22. if("ActiveXObject" in _1.global){
  23. var ms=function(n){
  24. return "MSXML"+n+".DOMDocument";
  25. };
  26. var dp=["Microsoft.XMLDOM",ms(6),ms(4),ms(3),ms(2)];
  27. _1.some(dp,function(p){
  28. try{
  29. _5=new ActiveXObject(p);
  30. }
  31. catch(e){
  32. return false;
  33. }
  34. return true;
  35. });
  36. if(_2&&_5){
  37. _5.async=false;
  38. _5.loadXML(_2);
  39. var pe=_5.parseError;
  40. if(pe.errorCode!==0){
  41. throw new Error("Line: "+pe.line+"\n"+"Col: "+pe.linepos+"\n"+"Reason: "+pe.reason+"\n"+"Error Code: "+pe.errorCode+"\n"+"Source: "+pe.srcText);
  42. }
  43. }
  44. if(_5){
  45. return _5;
  46. }
  47. }else{
  48. if(_4.implementation&&_4.implementation.createDocument){
  49. if(_2&&_1.trim(_2)&&_4.createElement){
  50. var _9=_4.createElement("xml");
  51. _9.innerHTML=_2;
  52. var _a=_4.implementation.createDocument("foo","",null);
  53. _1.forEach(_9.childNodes,function(_b){
  54. _a.importNode(_b,true);
  55. });
  56. return _a;
  57. }else{
  58. return _4.implementation.createDocument("","",null);
  59. }
  60. }
  61. }
  62. }
  63. return null;
  64. };
  65. dojox.xml.parser.textContent=function(_c,_d){
  66. if(arguments.length>1){
  67. var _e=_c.ownerDocument||_1.doc;
  68. dojox.xml.parser.replaceChildren(_c,_e.createTextNode(_d));
  69. return _d;
  70. }else{
  71. if(_c.textContent!==undefined){
  72. return _c.textContent;
  73. }
  74. var _f="";
  75. if(_c){
  76. _1.forEach(_c.childNodes,function(_10){
  77. switch(_10.nodeType){
  78. case 1:
  79. case 5:
  80. _f+=dojox.xml.parser.textContent(_10);
  81. break;
  82. case 3:
  83. case 2:
  84. case 4:
  85. _f+=_10.nodeValue;
  86. }
  87. });
  88. }
  89. return _f;
  90. }
  91. };
  92. dojox.xml.parser.replaceChildren=function(_11,_12){
  93. var _13=[];
  94. if(_1.isIE){
  95. _1.forEach(_11.childNodes,function(_14){
  96. _13.push(_14);
  97. });
  98. }
  99. dojox.xml.parser.removeChildren(_11);
  100. _1.forEach(_13,_1.destroy);
  101. if(!_1.isArray(_12)){
  102. _11.appendChild(_12);
  103. }else{
  104. _1.forEach(_12,function(_15){
  105. _11.appendChild(_15);
  106. });
  107. }
  108. };
  109. dojox.xml.parser.removeChildren=function(_16){
  110. var _17=_16.childNodes.length;
  111. while(_16.hasChildNodes()){
  112. _16.removeChild(_16.firstChild);
  113. }
  114. return _17;
  115. };
  116. dojox.xml.parser.innerXML=function(_18){
  117. if(_18.innerXML){
  118. return _18.innerXML;
  119. }else{
  120. if(_18.xml){
  121. return _18.xml;
  122. }else{
  123. if(typeof XMLSerializer!="undefined"){
  124. return (new XMLSerializer()).serializeToString(_18);
  125. }
  126. }
  127. }
  128. return null;
  129. };
  130. return dojox.xml.parser;
  131. });