dojox.data.OpmlStore

Author: Jared Jurkiewicz
since:V1.0

OpmlStore is a simple read-only store provided by Dojo and contained in the DojoX project. OpmlStore is a read interface to work with Opml formatted XML files. Similar to ItemFileReadStore, OpmlStore reads the contents from an http endpoint or a browser DOM object that contains Opml formatted data.

The following dojo.data APIs are implemented by OpmlStore

The following example shows an Opml data source:

<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
  <head>
    <title>geography.opml</title>
    <dateCreated>2006-11-10</dateCreated>
    <dateModified>2006-11-13</dateModified>
    <ownerName>Magellan, Ferdinand</ownerName>
  </head>
  <body>
    <outline text="Africa" type="continent">
      <outline text="Egypt" type="country"/>
      <outline text="Kenya" type="country">
        <outline text="Nairobi" type="city"/>
        <outline text="Mombasa" type="city"/>
      </outline>
      <outline text="Sudan" type="country">
        <outline text="Khartoum" type="city"/>
      </outline>
    </outline>
    <outline text="Asia" type="continent">
      <outline text="China" type="country"/>
      <outline text="India" type="country"/>
      <outline text="Russia" type="country"/>
      <outline text="Mongolia" type="country"/>
    </outline>
    <outline text="Australia" type="continent" population="21 million">
      <outline text="Australia" type="country" population="21 million"/>
    </outline>
    <outline text="Europe" type="continent">
      <outline text="Germany" type="country"/>
      <outline text="France" type="country"/>
      <outline text="Spain" type="country"/>
      <outline text="Italy" type="country"/>
    </outline>
    <outline text="North America" type="continent">
      <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">
        <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>
    <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>
      </outline>
      <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">
        <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>
        <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>
      </outline>
      <outline text="United States of America" type="country"/>
    </outline>
    <outline text="South America" type="continent">
      <outline text="Brazil" type="country" population="186 million"/>
      <outline text="Argentina" type="country" population="40 million"/>
    </outline>
  </body>
</opml>

Each data item is one of the <outline> tags. Each attribute on the outline acts as a attribute of the data item. For children tags, they are accessed via a special 'children' attribute. So, as expected by dojo.data, everything can be easily accessed via csvStore.getValue's'(), which makes it pluggable into dojo.data aware widgets.

Constructor Params

Parameter Required Description Since
url No This optional parameter specifies what URL from which to load the Opmldata Note that this URL is only loaded one time, as this is an in-memory data store. 1.0
data No A DOM of OPML data to use to populate the store. This parameter can be used instead of url. when you wish to load data differently then modify it to fit the expected Opml format. 1.0
label No A string that identifies which attribute to treat as the human-readable label. It must match one of the attributes on the <outline> tags for it to be effective. 1.0
urlPreventCache No Flag denoting whether or not browser caching should be avoided. Defaults to false. 1.4

Query Syntax

The query syntax used by dojox.data.OpmlStore is identical to the query syntax used by dojo.data.ItemFileReadStore

Query Options

Dojo.data defines support for a 'queryOptions' modifier object that affects the behavior of the query. The two defined options listed by the API are ignoreCase and deep. OpmlStore supports these options. The affect of these options on a query is defined below.

Option Result
ignoreCase The default is false. When set to true, the match on attributes is done in a case-insensitive fashion. This means with ignoreCase: true, a query of A* would match Apple and acorn
deep Default is false. By default, only root outline tags are matched. By setting to true, children tags are also scanned

Examples

Connecting OpmlStore to dijit.form.ComboBox

Note that dijit.form.ComboBox automatically passes the queryOption deep:true. This is because for ComboBox, hierarchy does not make sense, so searching as a flat list is preferable

dojo.require("dojox.data.OpmlStore");
dojo.require("dijit.form.ComboBox");
<div data-dojo-type="dojox.data.OpmlStore" data-dojo-props="url:'{{dataUrl}}dojox/data/tests/stores/geography.xml'" data-dojo-id="geoStore"></div>
<div data-dojo-type="dijit.form.ComboBox" data-dojo-props="store:geoStore, searchAttr:'text'"></div>

Connecting OpmlStore to dijit.Tree

Since Opml data can be hierarchical, the Tree widget is an excellent demo for it. A similar demo can be seen with ItemFileReadStore. here

dojo.require("dojox.data.OpmlStore");
dojo.require("dijit.Tree");
<div data-dojo-type="dojox.data.OpmlStore" data-dojo-props="url:'{{dataUrl}}dojox/data/tests/stores/geography.xml', label:'text'" data-dojo-id="geoStore2"></div>
<div data-dojo-type="dijit.tree.ForestStoreModel" data-dojo-id="geoModel" data-dojo-props="store:geoStore2, query:{}, rootId:'Geography', rootLabel:'Geography'"></div>
<div data-dojo-type="dijit.Tree" data-dojo-props="model:geoModel"></div>

Connecting OpmlStore to dojox.grid.DataGrid

Note here that as part of the DataGrid definition, the queryOption deep is set true. For the DataGrid, hierarchy here does not make sense

dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.OpmlStore");

var layoutGeo = [
  [
    { field: "text", name: "Name", width: 10 },
    { field: "type", name: "Geography Type", width: 10 },
    { field: "population", name: "Population", width: 'auto' }
  ]
];
<div data-dojo-type="dojox.data.OpmlStore" data-dojo-props="url:'{{dataUrl}}dojox/data/tests/stores/geography.xml', label:'text'" data-dojo-id="geoStore3"></div>

<div style="width: 400px; height: 300px;">
  <div id="grid"
    data-dojo-type="dojox.grid.DataGrid"
    data-dojo-props="store:geoStore3,
    structure:layoutGeo,
    query:{},
    queryOptions:{deep:true},
    rowsPerPage:40">
  </div>
</div>
@import "{{baseUrl}}dojox/grid/resources/Grid.css";
@import "{{baseUrl}}dojox/grid/resources/nihiloGrid.css";

.dojoxGrid table {
  margin: 0;
}