Xml.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-data-writer-Xml'>/**
  19. </span> * @author Ed Spencer
  20. * @class Ext.data.writer.Xml
  21. This class is used to write {@link Ext.data.Model} data to the server in an XML format.
  22. The {@link #documentRoot} property is used to specify the root element in the XML document.
  23. The {@link #record} option is used to specify the element name for each record that will make
  24. up the XML document.
  25. * @markdown
  26. */
  27. Ext.define('Ext.data.writer.Xml', {
  28. /* Begin Definitions */
  29. extend: 'Ext.data.writer.Writer',
  30. alternateClassName: 'Ext.data.XmlWriter',
  31. alias: 'writer.xml',
  32. /* End Definitions */
  33. <span id='Ext-data-writer-Xml-cfg-documentRoot'> /**
  34. </span> * @cfg {String} documentRoot The name of the root element of the document. Defaults to &lt;tt&gt;'xmlData'&lt;/tt&gt;.
  35. * If there is more than 1 record and the root is not specified, the default document root will still be used
  36. * to ensure a valid XML document is created.
  37. */
  38. documentRoot: 'xmlData',
  39. <span id='Ext-data-writer-Xml-cfg-defaultDocumentRoot'> /**
  40. </span> * @cfg {String} defaultDocumentRoot The root to be used if {@link #documentRoot} is empty and a root is required
  41. * to form a valid XML document.
  42. */
  43. defaultDocumentRoot: 'xmlData',
  44. <span id='Ext-data-writer-Xml-cfg-header'> /**
  45. </span> * @cfg {String} header A header to use in the XML document (such as setting the encoding or version).
  46. * Defaults to &lt;tt&gt;''&lt;/tt&gt;.
  47. */
  48. header: '',
  49. <span id='Ext-data-writer-Xml-cfg-record'> /**
  50. </span> * @cfg {String} record The name of the node to use for each record. Defaults to &lt;tt&gt;'record'&lt;/tt&gt;.
  51. */
  52. record: 'record',
  53. //inherit docs
  54. writeRecords: function(request, data) {
  55. var me = this,
  56. xml = [],
  57. i = 0,
  58. len = data.length,
  59. root = me.documentRoot,
  60. record = me.record,
  61. needsRoot = data.length !== 1,
  62. item,
  63. key;
  64. // may not exist
  65. xml.push(me.header || '');
  66. if (!root &amp;&amp; needsRoot) {
  67. root = me.defaultDocumentRoot;
  68. }
  69. if (root) {
  70. xml.push('&lt;', root, '&gt;');
  71. }
  72. for (; i &lt; len; ++i) {
  73. item = data[i];
  74. xml.push('&lt;', record, '&gt;');
  75. for (key in item) {
  76. if (item.hasOwnProperty(key)) {
  77. xml.push('&lt;', key, '&gt;', item[key], '&lt;/', key, '&gt;');
  78. }
  79. }
  80. xml.push('&lt;/', record, '&gt;');
  81. }
  82. if (root) {
  83. xml.push('&lt;/', root, '&gt;');
  84. }
  85. request.xmlData = xml.join('');
  86. return request;
  87. }
  88. });
  89. </pre>
  90. </body>
  91. </html>