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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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 * @extends Ext.data.writer.Writer
23 This class is used to write {@link Ext.data.Model} data to the server in an XML format.
24 The {@link #documentRoot} property is used to specify the root element in the XML document.
25 The {@link #record} option is used to specify the element name for each record that will make
30 Ext.define('Ext.data.writer.Xml', {
32 /* Begin Definitions */
34 extend: 'Ext.data.writer.Writer',
35 alternateClassName: 'Ext.data.XmlWriter',
41 <span id='Ext-data-writer-Xml-cfg-documentRoot'> /**
42 </span> * @cfg {String} documentRoot The name of the root element of the document. Defaults to <tt>'xmlData'</tt>.
43 * If there is more than 1 record and the root is not specified, the default document root will still be used
44 * to ensure a valid XML document is created.
46 documentRoot: 'xmlData',
48 <span id='Ext-data-writer-Xml-cfg-defaultDocumentRoot'> /**
49 </span> * @cfg {String} defaultDocumentRoot The root to be used if {@link #documentRoot} is empty and a root is required
50 * to form a valid XML document.
52 defaultDocumentRoot: 'xmlData',
54 <span id='Ext-data-writer-Xml-cfg-header'> /**
55 </span> * @cfg {String} header A header to use in the XML document (such as setting the encoding or version).
56 * Defaults to <tt>''</tt>.
60 <span id='Ext-data-writer-Xml-cfg-record'> /**
61 </span> * @cfg {String} record The name of the node to use for each record. Defaults to <tt>'record'</tt>.
66 writeRecords: function(request, data) {
71 root = me.documentRoot,
73 needsRoot = data.length !== 1,
78 xml.push(me.header || '');
80 if (!root && needsRoot) {
81 root = me.defaultDocumentRoot;
85 xml.push('<', root, '>');
88 for (; i < len; ++i) {
90 xml.push('<', record, '>');
92 if (item.hasOwnProperty(key)) {
93 xml.push('<', key, '>', item[key], '</', key, '>');
96 xml.push('</', record, '>');
100 xml.push('</', root, '>');
103 request.xmlData = xml.join('');