3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @class Ext.data.writer.Xml
18 * @extends Ext.data.writer.Writer
20 This class is used to write {@link Ext.data.Model} data to the server in an XML format.
21 The {@link #documentRoot} property is used to specify the root element in the XML document.
22 The {@link #record} option is used to specify the element name for each record that will make
27 Ext.define('Ext.data.writer.Xml', {
29 /* Begin Definitions */
31 extend: 'Ext.data.writer.Writer',
32 alternateClassName: 'Ext.data.XmlWriter',
39 * @cfg {String} documentRoot The name of the root element of the document. Defaults to <tt>'xmlData'</tt>.
40 * If there is more than 1 record and the root is not specified, the default document root will still be used
41 * to ensure a valid XML document is created.
43 documentRoot: 'xmlData',
46 * @cfg {String} defaultDocumentRoot The root to be used if {@link #documentRoot} is empty and a root is required
47 * to form a valid XML document.
49 defaultDocumentRoot: 'xmlData',
52 * @cfg {String} header A header to use in the XML document (such as setting the encoding or version).
53 * Defaults to <tt>''</tt>.
58 * @cfg {String} record The name of the node to use for each record. Defaults to <tt>'record'</tt>.
63 writeRecords: function(request, data) {
68 root = me.documentRoot,
70 needsRoot = data.length !== 1,
75 xml.push(me.header || '');
77 if (!root && needsRoot) {
78 root = me.defaultDocumentRoot;
82 xml.push('<', root, '>');
85 for (; i < len; ++i) {
87 xml.push('<', record, '>');
89 if (item.hasOwnProperty(key)) {
90 xml.push('<', key, '>', item[key], '</', key, '>');
93 xml.push('</', record, '>');
97 xml.push('</', root, '>');
100 request.xmlData = xml.join('');