XmlStore is a store provided by Dojo that is contained in the DojoX project. XmlStore is a read and write interface to basic XML data. XML is a common data interchange format and a store that can work with fairly generic XML documents is useful. The store is designed so that you can over-ride certain functions to get specific behaviors to occur when performing reads and saves.
The following dojo.data APIs are implemented by XmlStore
The following is an example of an XML document that this store can read:
A9B57C Title of 1 Author of 1 A9B57F Title of 2 Author of 2 A9B577 Title of 3 Author of 3 A9B574 Title of 4 Author of 4 A9B5CC Title of 5 Author of 5
The constructor for XmlStore takes the following possible parameters in its keyword arguments:
{"tag_name.item_attribute_name": "@xml_attribute_name", ...} This is optional. This is done so that attributes which are actual XML tag attributes (and not sub-tags of an XML tag), can be referenced.getLabel(). This is optional.The following functions can be over-ridden to alter save behavior, as described:
The fetch method query syntax for XmlStore is simple and straightforward. It allows for a list of attributes to match against in an AND fashion, just like ItemFileReadStore. For example, the following query object will locate all items that have attributes of those names that match both of those values:
{ foo:"bar", bit:"bite"}
Note that XmlStore supports the use of wild cards (multi-character * and single character ?) in its attribute value matching.
To find all items with attribute foo that start with bar, the query would be:
{ foo:"bar*"}
To find all items with attribute foo the value of which ends with ar and ignoring only the first character, the query would be:
{ foo:"?ar"}
NOTE: Other stores should follow the same query definition semantics for consistency.
For these examples, we'll assume a data source as defined by the example data format in this page.
var store = new dojox.data.XmlStore({url: "books.xml", rootItem: "book"});
var gotBooks = function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title");
}
}
var request = store.fetch({query: {isbn:"A9B57*"}, onComplete: gotBooks});
var store = new dojox.data.XmlStore({url: "books.xml", rootItem: "book"});
var gotBooks = function(items, request){
for (var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title");
}
}
var request = store.fetch({query: {isbn:"a9b57*"}, queryOptions: {ignoreCase: true}, onComplete: gotBooks});
For further examples see the test cases provided in dojox.data.tests.