zoukankan      html  css  js  c++  java
  • XML中定位字段修改、读取[原创]

      2004.10.01发表于blog.csdn.net/zxub

    function saveFile(fileName,xmlStr)//保存文本文件
    {
       var fso, tf,f;
       fso = new ActiveXObject("Scripting.FileSystemObject");
       try
     {
        f = fso.GetFile(fileName);
     f.attributes =0;
     }
     catch(e){}
       tf = fso.CreateTextFile(fileName, true);

       tf.Write(xmlStr);
       tf.Close();
    }

    function createDom(xmlStr)
    {
      var dom = new ActiveXObject("Msxml2.DOMDocument.3.0");
      //创建DOM实例,并装载文件
     dom.async="false";
      dom.loadXML(xmlStr);
     return dom;
    }

    function setValueByName(pTagName,pKeyName,pValue)
    {
     var xmlDom=createDom(openFile(GetXmlFilePath()));
     var pNodeList=xmlDom.getElementsByTagName(pTagName);
     var pchildNode=pNodeList.item(0).firstChild;
     for (j=1;;j++)
      {
       if (pchildNode.nodeName==pKeyName)
       {
        pchildNode.text=pValue;
        break;
       }
       pchildNode=pchildNode.nextSibling;
      }
     var xmlStr=xmlDom.xml;
     xmlStr=xmlStr.replace("<?xml version=\"1.0\"?>","<?xml version=\"1.0\" encoding=\"gb2312\"?>")
     saveFile(GetXmlFilePath(),xmlStr);
    }
    function getValueByName(pTagName,pKeyName)
    {
     var xmlDom=createDom(openFile(GetXmlFilePath()));
     var pNodeList=xmlDom.getElementsByTagName(pTagName);
     var pchildNode=pNodeList.item(0).firstChild;
     var pValue=100;
        for (j=1;;j++)
      {
       if (pchildNode.nodeName==pKeyName)
       {
        pValue=pchildNode.text;
        return pValue;
        break;
       }
       pchildNode=pchildNode.nextSibling;
      }
    }

  • 相关阅读:
    插入排序-Java
    选择排序-java
    逻辑回归----梯度上升
    logistic回归----- 随机梯度下降法
    JAVA实现聚类指标的计算Purity、NMI、RI、Precision、Recall、F值。
    Python 条形图绘制
    java中接口的注意事项
    算法-双向队列
    算法-manacher-最长回文子串-1
    算法-kmp-1
  • 原文地址:https://www.cnblogs.com/zxub/p/173600.html
Copyright © 2011-2022 走看看