3 * @class Ext.data.writer.Xml
4 * @extends Ext.data.writer.Writer
6 This class is used to write {@link Ext.data.Model} data to the server in an XML format.
7 The {@link #documentRoot} property is used to specify the root element in the XML document.
8 The {@link #record} option is used to specify the element name for each record that will make
13 Ext.define('Ext.data.writer.Xml', {
15 /* Begin Definitions */
17 extend: 'Ext.data.writer.Writer',
18 alternateClassName: 'Ext.data.XmlWriter',
25 * @cfg {String} documentRoot The name of the root element of the document. Defaults to <tt>'xmlData'</tt>.
26 * If there is more than 1 record and the root is not specified, the default document root will still be used
27 * to ensure a valid XML document is created.
29 documentRoot: 'xmlData',
32 * @cfg {String} defaultDocumentRoot The root to be used if {@link #documentRoot} is empty and a root is required
33 * to form a valid XML document.
35 defaultDocumentRoot: 'xmlData',
38 * @cfg {String} header A header to use in the XML document (such as setting the encoding or version).
39 * Defaults to <tt>''</tt>.
44 * @cfg {String} record The name of the node to use for each record. Defaults to <tt>'record'</tt>.
49 writeRecords: function(request, data) {
54 root = me.documentRoot,
56 needsRoot = data.length !== 1,
61 xml.push(me.header || '');
63 if (!root && needsRoot) {
64 root = me.defaultDocumentRoot;
68 xml.push('<', root, '>');
71 for (; i < len; ++i) {
73 xml.push('<', record, '>');
75 if (item.hasOwnProperty(key)) {
76 xml.push('<', key, '>', item[key], '</', key, '>');
79 xml.push('</', record, '>');
83 xml.push('</', root, '>');
86 request.xmlData = xml.join('');