    DataWriter
      XmlWriter

# Class Ext.data.XmlWriter

Package: | Ext.data
Defined In: | XmlWriter.js
Class: | XmlWriter
Extends: | DataWriter

DataWriter extension for writing an array or single Ext.data.Record object(s) in preparation for executing a remote CRUD action via XML. XmlWriter uses an instance of Ext.XTemplate for maximum flexibility in defining your own custom XML schema if the default schema is not appropriate for your needs. See the tpl configuration-property.

## Config Options

Config Options | Defined By
--- | ---
| createRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.createRecord) | DataWriter
| destroyRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.destroyRecord) | DataWriter
| documentRoot : String [xrequest] (Optional) The name of the XML document root-node. Note: this parameter is required only when sending ext... [xrequest] (Optional) The name of the XML document root-node. Note: this parameter is required only when sending extra baseParams to the server during a write-request -- if no baseParams are set, the Ext.data.XmlReader.record meta-property can suffice as the XML document root-node for write-actions involving just a single record. For requests involving multiple records and NO baseParams, the Ext.data.XmlWriter.root property can act as the XML document root. | XmlWriter
| forceDocumentRoot : Boolean [false] Set to true to force XML documents having a root-node as defined by documentRoot, even with no baseParams def... [false] Set to `true` to force XML documents having a root-node as defined by documentRoot, even with no baseParams defined. | XmlWriter
| listful : Boolean false by default. Set true to have the DataWriter always write HTTP params as a list, even when acting upon a single... `false` by default. Set `true` to have the DataWriter always write HTTP params as a list, even when acting upon a single record. | DataWriter
| root : String [records] The name of the containing element which will contain the nodes of an write-action involving multiple recor... [records] The name of the containing element which will contain the nodes of an write-action involving multiple records. Each xml-record written to the server will be wrapped in an element named after Ext.data.XmlReader.record property. eg: `
    <?xml version="1.0" encoding="UTF-8"?>
    <user><first>Barney</first></user>
` However, when multiple records are written in a batch-operation, these records must be wrapped in a containing Element. eg: `
    <?xml version="1.0" encoding="UTF-8"?>
        <records>
            <first>Barney</first></user>
            <records><first>Barney</first></user>
        </records>
` Defaults to `records`. Do not confuse the nature of this property with that of documentRoot | XmlWriter
| tpl : String/Ext.XTemplate The XML template used to render write-actions to your server. One can easily provide his/her own custom template-defi... The XML template used to render write-actions to your server. One can easily provide his/her own custom template-definition if the default does not suffice. Defaults to: `
    <?xml version="{version}" encoding="{encoding}"?>
        <tpl if="documentRoot"><{documentRoot}>
        <tpl for="baseParams">
            <tpl for=".">
                <{name}>{value}</{name}>
            </tpl>
        </tpl>
        <tpl if="records.length > 1"><{root}>',
        <tpl for="records">
            <{parent.record}>
            <tpl for=".">
                <{name}>{value}</{name}>
            </tpl>
            </{parent.record}>
        </tpl>
        <tpl if="records.length > 1"></{root}></tpl>
        <tpl if="documentRoot"></{documentRoot}></tpl>
` Templates will be called with the following API {String} version [1.0] The xml version. {String} encoding [ISO-8859-15] The xml encoding. {String/false} documentRoot The XML document root-node name or `false` if not required. See documentRoot and forceDocumentRoot. {String} record The meta-data parameter defined on your Ext.data.XmlReader.record configuration represents the name of the xml-tag containing each record. {String} root The meta-data parameter defined by Ext.data.XmlWriter.root configuration-parameter. Represents the name of the xml root-tag when sending multiple records to the server. {Array} records The records being sent to the server, ie: the subject of the write-action being performed. The records parameter will be always be an array, even when only a single record is being acted upon. Each item within the records array will contain an array of field objects having the following properties: {String} name The field-name of the record as defined by your Ext.data.Record definition. The "mapping" property will be used, otherwise it will match the "name" property. Use this parameter to define the XML tag-name of the property. {Mixed} value The record value of the field enclosed within XML tags specified by name property above. {Array} baseParams. The baseParams as defined upon Ext.data.Store.baseParams. Note that the baseParams have been converted into an array of [{name : "foo", value: "bar"}, ...] pairs in the same manner as the records parameter above. See documentRoot and forceDocumentRoot. | XmlWriter
| updateRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.updateRecord | DataWriter
| writeAllFields : Boolean false by default. Set true to have DataWriter return ALL fields of a modified record -- not just those that changed.... `false` by default. Set `true` to have DataWriter return ALL fields of a modified record -- not just those that changed. `false` to have DataWriter only request modified fields from a record. | DataWriter
| xmlEncoding : String [ISO-8859-15] The `encoding` written to header of xml documents. `
    <?xml version="1.0" encoding="ISO-8859-15"?>
` | XmlWriter
| xmlVersion : String [1.0] The `version` written to header of xml documents. `
    <?xml version="1.0" encoding="ISO-8859-15"?>
` | XmlWriter

## Public Properties

This class has no public properties.

## Public Methods

Method | Defined By
--- | ---
| apply( `Object params`, `Object baseParams`, `String action`, `Record/Record[] rs` ) : void Compiles a Store recordset into a data-format defined by an extension such as Ext.data.JsonWriter or Ext.data.XmlWrit... Compiles a Store recordset into a data-format defined by an extension such as Ext.data.JsonWriter or Ext.data.XmlWriter in preparation for a server-write action. The first two params are similar similar in nature to Ext.apply, Where the first parameter is the receiver of paramaters and the second, baseParams, the source. Parameters: `params` : Object The request-params receiver. `baseParams` : Object as defined by Ext.data.Store.baseParams. The baseParms must be encoded by the extending class, eg: Ext.data.JsonWriter, Ext.data.XmlWriter. `action` : String [create|update|destroy] `rs` : Record/Record[] The recordset to write, the subject(s) of the write action. Returns: void | DataWriter
| createRecord( `Ext.data.Record rec` ) : Array createRecord createRecord Parameters: `rec` : Ext.data.Record Returns: `Array` Array of <tt>name:value</tt> pairs for attributes of the {@link Ext.data.Record}. See {@link Ext.data.DataWriter#toHash}. | XmlWriter
| destroyRecord( `Ext.data.Record rec` ) : Array destroyRecord destroyRecord Parameters: `rec` : Ext.data.Record Returns: `Array` Array containing a attribute-object (name/value pair) representing the {@link Ext.data.DataReader#idProperty idProperty}. | XmlWriter
| render( `Object params`, `Object baseParams`, `Object/Object[] data` ) : void XmlWriter implementation of the final stage of a write action. XmlWriter implementation of the final stage of a write action. Parameters: `params` : Object Transport-proxy's (eg: Ext.Ajax.request) params-object to write-to. `baseParams` : Object as defined by Ext.data.Store.baseParams. The baseParms must be encoded by the extending class, eg: Ext.data.JsonWriter, Ext.data.XmlWriter. `data` : Object/Object[] Data-object representing the compiled Store-recordset. Returns: void | XmlWriter
| toArray( `Hash data` ) : [Object] Converts a Hashed Ext.data.Record to fields-array array suitable for encoding to xml via XTemplate, eg: &lt;tpl for="... Converts a Hashed Ext.data.Record to fields-array array suitable for encoding to xml via XTemplate, eg: `
    <tpl for="."><{name}>{value}</{name}</tpl>
` eg, non-phantom: `
    {id: 1, first: 'foo', last: 'bar'} --> [{name: 'id', value: 1}, {name: 'first', value: 'foo'}, {name: 'last', value: 'bar'}]
` Phantom records will have had their idProperty omitted in toHash if determined to be auto-generated. Non AUTOINCREMENT pks should have been protected. Parameters: `data` : Hash Hashed by Ext.data.DataWriter#toHash Returns: `[Object]` Array of attribute-objects. | DataWriter
| toHash( `Ext.data.Record` , `Object config` ) : Object Converts a Record to a hash, taking into account the state of the Ext.data.Record along with configuration properties... Converts a Record to a hash, taking into account the state of the Ext.data.Record along with configuration properties related to its rendering, such as writeAllFields, phantom, getChanges and idProperty Parameters: `` : Ext.data.Record `config` : Object NOT YET IMPLEMENTED. Will implement an exlude/only configuration for fine-control over which fields do/don't get rendered. Returns: `Object` | DataWriter
| updateRecord( `Ext.data.Record rec` ) : Array updateRecord updateRecord Parameters: `rec` : Ext.data.Record Returns: `Array` Array of {name:value} pairs for attributes of the {@link Ext.data.Record}. See {@link Ext.data.DataWriter#toHash}. | XmlWriter

## Public Events

This class has no public events.