dataschema-xml.js revision 1fad80225c335240e31e0350a65463a0bd7a9b1a
/**
* Provides a DataSchema implementation which can be used to work with XML data.
*
* @module dataschema
* @submodule dataschema-xml
*/
/**
* XML subclass for the DataSchema Utility.
* @class DataSchema.XML
* @extends DataSchema.Base
* @static
*/
SchemaXML = {
/////////////////////////////////////////////////////////////////////////////
//
// DataSchema.XML static methods
//
/////////////////////////////////////////////////////////////////////////////
/**
* Applies a given schema to given XML data.
*
* @method apply
* @param schema {Object} Schema to apply.
* @param data {XMLDoc} XML document.
* @return {Object} Schema-parsed data.
* @static
*/
if(xmldoc && xmldoc.nodeType && (9 === xmldoc.nodeType || 1 === xmldoc.nodeType || 11 === xmldoc.nodeType) && schema) {
// Parse results data
// Parse meta data
}
else {
}
return data_out;
},
/**
* Get an XPath-specified value for a given field from an XML node or document.
*
* @method _getLocationValue
* @param field {String | Object} Field definition.
* @param context {Object} XML node or document to search within.
* @return {Object} Data value or null.
* @static
* @protected
*/
try {
}
}
catch(e) {
}
return null;
},
/**
* Fetches the XPath-specified result for a given location in an XML node or document.
*
* @param locator {String} The XPath location.
* @param context {Object} XML node or document to search within.
* @param xmldoc {Object} XML document to resolve namespace.
* @return {Object} Data collection or null.
* @static
* @protected
*/
// Standards mode
return xmldoc.evaluate(locator, context, xmldoc.createNSResolver(context.ownerDocument ? context.ownerDocument.documentElement : context.documentElement), 0, null);
}
// IE mode
else {
var values=[], locatorArray = locator.split(/\b\/\b/), i=0, l=locatorArray.length, location, subloc, m, isNth;
// XPath is supported
try {
// this fixes the IE 5.5+ issue where childnode selectors begin at 0 instead of 1
}
// Fallback for DOM nodes and fragments
catch (e) {
// Iterate over each locator piece
for (; i<l && context; i++) {
location = locatorArray[i];
// grab nth child []
//XPath is 1-based while DOM is 0-based
subloc--;
isNth = true;
}
// grab attribute value @
}
// grab that last instance of tagName
}
// find the last matching location in children
else if (l != i + 1) {
m = -1;
}
}
}
}
if (context) {
// attribute
}
// nth child
else if (isNth) {
}
// all children
else {
}
}
}
// returning a mock-standard object for IE
return {
index: 0,
iterateNext: function() {
this.index += 1;
return result;
},
};
}
},
/**
* Schema-parsed result field.
*
* @method _parseField
* @param field {String | Object} Required. Field definition.
* @param result {Object} Required. Schema parsed data object.
* @param context {Object} Required. XML node or document to search within.
* @static
* @protected
*/
result[field.key] = SchemaXML._parseResults.call(this, field.schema, context, {results:[],meta:{}}).results;
}
else {
}
},
/**
* Parses results data according to schema
*
* @method _parseMeta
* @param xmldoc_in {Object} XML document parse.
* @param data_out {Object} In-progress schema-parsed data to update.
* @return {Object} Schema-parsed data.
* @static
* @protected
*/
var key,
for(key in metaFields) {
}
}
}
return data_out;
},
/**
* Schema-parsed result to add to results list.
*
* @method _parseResult
* @param fields {Array} Required. A collection of field definition.
* @param context {Object} Required. XML node or document to search within.
* @return {Object} Schema-parsed data.
* @static
* @protected
*/
var result = {}, j;
// Find each field value
}
return result;
},
/**
* Schema-parsed list of results from full data
*
* @method _parseResults
* @param schema {Object} Schema to parse against.
* @param context {Object} XML node or document to parse.
* @param data_out {Object} In-progress schema-parsed data to update.
* @return {Object} Schema-parsed data.
* @static
* @protected
*/
results = [],
// loop through each result node
}
}
else {
// loop through the nodelist
i += 1;
}
}
}
else {
}
}
return data_out;
}
};