|
// LimitedXML class
/**
* Class for storing and accessing shared data in XML.
* @param applicationIdentifier identifier for Application object to share data.
* @param nMax maximum quantity of items to store.
*/
function LimitedXML(applicationIdentifier, nMax) {
this.add = LimitedXML_add;
this.getXMLDocument = LimitedXML_getXMLDocument;
this.getItems = LimitedXML_getItems;
this.applicationIdentifier = applicationIdentifier;
this.removeSuperfluous = LimitedXML_removeSuperfluous;
this.xmlSection = "ITEM";
this.nMax = nMax;
}
/**
* Add new item.
* @param value value to add.
*/
function LimitedXML_add(value) {
var xmlDoc = this.getXMLDocument();
var element = xmlDoc.createElement(this.xmlSection);
var elementText = xmlDoc.createTextNode(value);
var root = xmlDoc.firstChild;
root.appendChild(element);
element.appendChild(elementText);
this.removeSuperfluous(root);
}
/**
* Removes superfluous items.
* @param root XML node for the root.
*/
function LimitedXML_removeSuperfluous(root) {
var items = this.getItems();
if(this.nMax < items.length) {
root.removeChild(items.item(0));
}
}
/**
* Queries list of data items.
* @return XMLNodesList of managed items.
*/
function LimitedXML_getItems() {
var xmlDoc = this.getXMLDocument();
var itemsList = xmlDoc.getElementsByTagName(this.xmlSection);
return itemsList;
}
/**
* Provides access and first time creation of shared XML Document.
* @return Shared FreeThreadedDOMDocument object.
*/
function LimitedXML_getXMLDocument() {
var xmlDoc = Application(this.applicationIdentifier);
if(typeof(xmlDoc) == "undefined") {
xmlDoc = new ActiveXObject("MSXML.FreeThreadedDOMDocument");
var rootElement=xmlDoc.createElement("ROOT");
xmlDoc.appendChild(rootElement);
Application(this.applicationIdentifier) = xmlDoc;
}
return xmlDoc;
}
// LimitedXML class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.