|
// SharedXML class.
function SharedXML() {
this.addNode = SharedXML_addNode;
this.findNode = SharedXML_findNode;
this.findNodeByName = SharedXML_findNodeByName;
this.removeNode = SharedXML_removeNode;
this.getXMLDocument = SharedXML_getXMLDocument;
this.setAttribte = SharedXML_setAttribte;
this.getItems = SharedXML_getItems;
this.applicationIdentifier = "USERS";
this.xmlSection = "USER";
}
/**
* Add new xml node in shared xml. Assign new id to this node.
* @return Newly created xml node.
*/
function SharedXML_addNode() {
var xmlDoc = this.getXMLDocument();
var root = xmlDoc.firstChild;
var element = xmlDoc.createElement(this.xmlSection);
root.appendChild(element);
var now = new Date();
var id = now.valueOf();
this.setAttribte(element, "ID", id);
return element;
}
/**
* Create or rename name-value pair of attribute.
* @param name the attribute name.
* @param value attribute value.
*/
function SharedXML_setAttribte(xmlNode, name, value) {
var attributeNode = xmlNode.attributes.getNamedItem(name);
if(attributeNode != null) {
attributeNode.nodeValue = value;
}
else {
var xmlDoc = xmlNode.ownerDocument;
attributeNode = xmlDoc.createAttribute(name);
attributeNode.nodeValue = value;
xmlNode.attributes.setNamedItem(attributeNode);
}
}
/**
* Find node by id.
* @param id unique id to search.
* @return XML node if found or undefined value;
*/
function SharedXML_findNode(id) {
var xmlDoc = this.getXMLDocument();
xmlDoc.setProperty("SelectionLanguage", "XPath");
var root = xmlDoc.firstChild;
var queryString = "*[@ID=" + id + "]";
return root.selectSingleNode(queryString);
}
/**
* Find node by name.
* @param name unique name to search.
* @return XML node if found or undefined value;
*/
function SharedXML_findNodeByName(name) {
var xmlDoc = this.getXMLDocument();
xmlDoc.setProperty("SelectionLanguage", "XPath");
var root = xmlDoc.firstChild;
var queryString = "*[@NAME=\"" + name + "\"]";
return root.selectSingleNode(queryString);
}
/**
* Removes specified node.
* @param xmlNode node to delete.
*/
function SharedXML_removeNode(xmlNode) {
var xmlDoc = this.getXMLDocument();
var root = xmlDoc.firstChild;
root.removeChild(xmlNode);
}
/**
* Provides access and first time creation of shared XML Document.
* @return Shared FreeThreadedDOMDocument object.
*/
function SharedXML_getXMLDocument() {
if(typeof(Application) != "undefined") {
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;
}
else {
// Testing purposes only.
var xmlDoc = app;
if(typeof(xmlDoc) == "undefined") {
xmlDoc = WScript.CreateObject("MSXML.FreeThreadedDOMDocument");
var rootElement=xmlDoc.createElement("ROOT");
xmlDoc.appendChild(rootElement);
app = xmlDoc;
}
return xmlDoc;
}
}
var app;
/**
* Queries list of data items.
* @return XMLNodesList of managed items.
*/
function SharedXML_getItems() {
var xmlDoc = this.getXMLDocument();
var itemsList = xmlDoc.getElementsByTagName(this.xmlSection);
return itemsList;
}
// SharedXML 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.