织梦CMS - 轻松建站从此开始!

罗索实验室

当前位置: 主页 > 行业动态 > 『互联网』 >

Source code for unixml for javascript(1)

罗索客 发布于 2002-05-20 18:31 点击:次 
// **************************************** // Implementation of UniXML // Purpose: The UniXML component is designed to facilitate the manipulation of XML data // Author: Richard Chien2000/09/07 // Modification History: //1. 2000/09/13add two methods
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)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www1.rosoo.net/a/200205/4032.html]
本文出处: 作者:lucy
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容