zoukankan      html  css  js  c++  java
  • VBS操作XML文档,拷贝结点 (转)

    Dim xmlDoc,xmlRoot,xmlNode,lastNode,newNode
    Dim doc,docRoot,i,flag
    Dim strNodeName,strPath,docPath
    Dim xmlFolder,docFolder,oshell
    Set oshell = CreateObject("Shell.Application")
    Set xmlFolder = oshell.BrowseForFolder(0, "选择目标XML文档所在的目录", 0, ssfDRIVES)
      strPath = xmlFolder.Self.Path & "\jz-mapping.xml"
    Set docFolder = oshell.BrowseForFolder(0,"请选择源XML文档所在的目录",0,ssfDRIVES)
      docPath = docFolder.Self.Path & "\jz-mapping.xml"
    strNodeName = InputBox ("请输入要拷贝的结点ID值","输入ID值")

    flag = True
    Rem 加载目标文件
    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    xmlDoc.async = False
    xmlDoc.load strPath
    If xmlDoc.parseError.errorCode <> 0 Then
      Wscript.Echo "错误:" & Chr(13) & xmlDoc.parseError.reason
    End If
    Set xmlRoot = xmlDoc.documentElement

    i = 0
    Do While i<xmlRoot.childNodes.length
    Set newNode = xmlRoot.childNodes.item(i)
      If newNode.getAttribute("id") = strNodeName Then
      flag = False
      Exit Do
        Else
      i = i + 1
      End If
    loop

    If flag Then 
        Rem 加载源文件,查找要拷贝的结点
        Set doc =CreateObject("Microsoft.XMLDOM")
        doc.async = False
        doc.load docPath
        If doc.parseError.errorCode <> 0 Then
        Wscript.Echo "错误:" & Chr(13) & doc.parseError.reason
        End If
        Set docRoot = doc.documentElement
        i = 0
        Do While i < docRoot.childNodes.length
        Set newNode = docRoot.childNodes.item(i)
        If newNode.getAttribute("id") = strNodeName Then
        Exit Do
        Else
        i = i + 1
        End If
        loop
       
        Set lastNode = xmlRoot.lastChild
        xmlDoc.documentElement.insertBefore newNode,lastNode
        xmlDoc.Save strPath
    Else
    MsgBox  "已存在要拷贝的结点!",,"Bug提示"
    End If

    上次发的那个要在CMD下运行,还要传参数
    这个在运行时会弹出相应的对话框
    方便了操作

    (原 http://hipeace87.iteye.com/blog/290520

  • 相关阅读:
    001.云桌面整体解决方案实施
    Netty基础招式——ChannelHandler的最佳实践
    架构设计之数据分片
    Go是一门什么样的语言?
    Jenkins汉化配置
    Window安装构建神器Jenkins
    uni-app&H5&Android混合开发三 || uni-app调用Android原生方法的三种方式
    如何使用Hugging Face中的datasets
    关于torch.nn.LSTM()的输入和输出
    pytorch中的nn.CrossEntropyLoss()计算原理
  • 原文地址:https://www.cnblogs.com/ryhan/p/2036540.html
Copyright © 2011-2022 走看看