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