zoukankan      html  css  js  c++  java
  • AutoIt with XML: Add a child/grandchild node or remove any node

    Sometimes, we have to use AutoIt script to edit an xml, add a node or remove a node, to make some deployment documents fitable to some project.

    I have picked up a piece of script function about it as below:

    Func append_node($SourceFile)
        $objDom = ObjCreate("Microsoft.XMLDOM")
        $objDom.load($SourceFile)
        $objRoot = $objDom.documentElement.selectSingleNode('//Left')
    
        ;Add a child node
        $child1 = $objDom.createElement("rootElement")
        $child1.text = "Child1"
        $child1.setAttribute("Att1Child1","Child1_TextAtt1")
        $objRoot.appendChild($child1)
    
        ;Add a grandchild node
        $objChild1 = $objDom.createElement("childElement1")
        $objChild1.text = "objChild1"
        $objChild1.setAttribute("Att1ObjChild1","obj_Child1_TextAtt1")
        $child1.appendChild($objChild1)
    
        ;Add a grandchild node
        $objChild2 = $objDom.createElement("childElement2")
        $objChild2.text = "objChild2"
        $objChild2.setAttribute("Att2ObjChild2","obj_Child2_TextAtt21")
        $child1.appendChild($objChild2)
    
        $objDom.save($SourceFile)
    EndFunc
    
    Func remove_node($SourceFile)
        $oXML = ObjCreate("Microsoft.XMLDOM")
        $oXML.Load($SourceFile)
        $oNode = $oXML.documentElement.selectSingleNode('//Left')
        ;$oNode.parentNode.removeChild($oNode)
        $remove_node = $oXML.documentElement.selectSingleNode('//Left/NewChild1')
        ;Remove the child node
        $oNode.removeChild($remove_node)
        $oXML.save($SourceFile)
    EndFunc
    
    
    $SourceFile = "STRPControl.xml"
    append_node($SourceFile)
  • 相关阅读:
    angularJs项目实战!02:前端的页面分解与组装
    angularJs项目实战!01:模块划分和目录组织
    django admin 导出数据简单示例
    django 学习之model操作(想细化)
    6.11大杂烩。。
    InlineModelAdmin对象的学习
    django-salmonella的使用
    python 保留两位小数
    Django 时间与时区设置问题
    Django学习
  • 原文地址:https://www.cnblogs.com/autotest/p/3483981.html
Copyright © 2011-2022 走看看