XML

Utility methods for manipulating XML data.

Summary
Utility methods for manipulating XML data.
Creates an instance of the mojo.helper.XML class
Private function--Parses an XML node as a JavaScript object
Private function--Returns a string representation of an XML node
Parameters for XML manipulations.
{Boolean} Determines whether or not the XML parser will treat unique nodes who are children of a parent with a plural nodeName, or children of a node with a total attribute, as those which should form part of an array.

Functions

constructor

constructor: function(xml,
params)

Creates an instance of the mojo.helper.XML class

Parameters

xml{string|XmlDocument} The XML to convert to a JavaScript object.
params{<mojo.helper.XML.params>} Optional parameters.

Example

// instantiate new XML
var xml = new mojo.helper.XML("<?xml version="1.0" encoding="UTF-8"?><nodes><upon/></nodes>");

parseNode

_parseNode: function(node)

Private function--Parses an XML node as a JavaScript object

Parameters

node{Element|Text|CDATASection} The node to parse

Returns

A JavaScript object representation of the XML node

_nodeToString

_nodeToString: function(node)

Private function--Returns a string representation of an XML node

Parameters

node{Element|Text|CDATASection} The node to parse

Returns

A string representation of the XML node

XML. params

Parameters for XML manipulations.

Summary
{Boolean} Determines whether or not the XML parser will treat unique nodes who are children of a parent with a plural nodeName, or children of a node with a total attribute, as those which should form part of an array.

Properties

inferArrays

{Boolean} Determines whether or not the XML parser will treat unique nodes who are children of a parent with a plural nodeName, or children of a node with a total attribute, as those which should form part of an array.  Defaults to true.

Example

// Nodes who are children of a parent with a plural nodeName
var objectWithInference = mojo.helpers.XML.toObject('<nodes><a>All By Myself</a></nodes>', { inferArrays: true }); // => {nodes: { a: ['All By Myself'] } }
var objectWithoutInference = mojo.helpers.XML.toObject('<nodes><a>All By Myself</a></nodes>', { inferArrays: false }); // => {nodes: { a: 'All By Myself' } }

// Nodes whose parent has a total attribute
var objectWithInference = mojo.helpers.XML.toObject('<review_array total="1"><review>All By Myself</review></review_array>', { inferArrays: true }); // => {review_array: { review: ['All By Myself'] } }
var objectWithoutInference = mojo.helpers.XML.toObject('<review_array total="1"><review>All By Myself</review></review_array>', { inferArrays: false }); // => {review_array: { review: 'All By Myself' } }
constructor: function(xml,
params)
Creates an instance of the mojo.helper.XML class
_parseNode: function(node)
Private function--Parses an XML node as a JavaScript object
_nodeToString: function(node)
Private function--Returns a string representation of an XML node