Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Writing ASP Chat using JavaScript and XML (Part 4)

, 21 Jan 2004
The last part of the ASP chat series. This article explains how to provide a chat with multiple rooms.
// 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(xmlNode, nMax) {
	this.add = LimitedXML_add;
	//this.getXMLDocument = LimitedXML_getXMLDocument; 
	// replaced with getWorkingNode()
	this.getWorkingNode = LimitedXML_getWorkingNode;
	this.getItems = LimitedXML_getItems;
	this.removeSuperfluous = LimitedXML_removeSuperfluous;
	this.xmlNode = xmlNode;
	this.xmlSection = "ITEM";
	this.nMax = nMax;
}

/**
 *  Add new item.
 *  @param value value to add.
 */
function LimitedXML_add(value) {
	var workingNode = this.getWorkingNode();
	var xmlDoc = workingNode.ownerDocument;
	var element = xmlDoc.createElement(this.xmlSection);
	var elementText = xmlDoc.createTextNode(value);
	workingNode.appendChild(element);
	element.appendChild(elementText);
	this.removeSuperfluous(workingNode);
}

/**
 *  Removes superfluous items.
 *  @param parentNode XML node for the root.
 */
function LimitedXML_removeSuperfluous(parentNode) {
	var items = this.getItems();
	if(this.nMax < items.length) {
		parentNode.removeChild(items.item(0));
	}
}

/**
 *  Queries list of data items.
 *  @return XMLNodesList of managed items.
 */
function LimitedXML_getItems() {
	var workingNode = this.getWorkingNode();
	var itemsList = workingNode.childNodes;
	return itemsList;
}


/**
 *  Provides access to managed xml node.
 */
function LimitedXML_getWorkingNode() {
	return this.xmlNode;
}
/**
 *  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 = Server.CreateObject("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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alexander Fedorenko
Web Developer
Ukraine Ukraine
Alexander Fedorenko is a professional C++ developer since 1996. He completed many custom and shareware projects. One of the successful projects is DevPlanner - tool for personal planning and time management.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 22 Jan 2004
Article Copyright 2004 by Alexander Fedorenko
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid