TAG:
// **************************************** // Implementation of UniXML // Purpose: The UniXML component is designed to facilitate the manipulation of XML data // Author: Richard Chien 2000/09/07 // Modification History: // 1. 2000/09/13 add two methods AppendChild() and AppendSibling() // 2. 2000/09/14 add Extract() // 3. 2000/09/18 add ExtractFullPath(); change Extract() as ExtractPartialPath() // **************************************** function UniXML() { // Attributes this.XMLDoc = new ActiveXObject("Microsoft.XMLDOM"); this.XMLDoc.async = false; this.XMLDoc.loadXML('' // Methods this.LoadXML = LoadXML; this.GetXML = GetXML; this.ResetContent = ResetContent; this.Generate = Generate; this.Query = Query; this.GeneratePath = GeneratePath; this.GenerateAttribute = GenerateAttribute; this.QueryAttribute = QueryAttribute; this.Delete = Delete; this.GetMRSCount = GetMRSCount; this.AppendChild = AppendChild; this.AppendSibling = AppendSibling; this.Merge = Merge; this.ExtractPartialPath = ExtractPartialPath; this.ExtractFullPath = ExtractFullPath; } function gFunCloneUniXML(unixml) { var xmldoc = unixml.XMLDoc.cloneNode(true); var unixml = new UniXML(); unixml.LoadXML(xmldoc.xml); return unixml; } function LoadXML(strXML) { var blnRet = this.XMLDoc.loadXML(strXML); if (blnRet == false) throw "[UniXML Err]: LoadXML\\n Invalid XML document."; } function GetXML() { return this.XMLDoc.xml; } function ResetContent() { this.XMLDoc.loadXML('' } function Generate(strPattern, strContent) { try { strContent += ""; // Cast strContent to the string type //if (strContent == "") return false; var strParentPattern, strChildPattern; var strTag; var ndParent, ndChild, ndText; var ndx; ndx = strPattern.lastIndexOf("/"); // find out the index of the last occurance of ''/'' if (ndx == -1) { strParentPattern = "/UniMSG"; strChildPattern = "/UniMSG/" + strPattern; strTag = strPattern; } else { strParentPattern = "/UniMSG/" + strPattern.substring(0, ndx); strChildPattern = "/UniMSG/" + strPattern; strTag = strPattern.substr(ndx + 1); } ndParent = this.XMLDoc.selectSingleNode(strParentPattern); if (ndParent == null) throw "[UniXML Err]: Generate\\n Invalid access pattern ''" + strParentPattern + "''"; ndChild = this.XMLDoc.selectSingleNode(strChildPattern); if (ndChild == null) // the node doesn''t exist, so create it. { if (strContent == "") return false; //ndChild = this.XMLDoc.documentElement.ownerDocument.createNode(1, strTag, this.XMLDoc.lastChild.namespaceURI); ndChild = this.XMLDoc.createNode(1, strTag, this.XMLDoc.lastChild.namespaceURI); ndText = this.XMLDoc.createTextNode(strContent); ndChild.appendChild(ndText); ndParent.appendChild(ndChild); } else { ndChild.text = strContent; } return true; } catch (e) { throw e; } } function Query(strPattern) { try { var nd; nd = this.XMLDoc.selectSingleNode("/UniMSG/" + strPattern); if (nd == null) return ""; return nd.text; } catch (e) { throw e; } } (lucy) |