• 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)
  • 相关阅读:
    Reporting Services 配置工具
    管道符、重定向和环境变量
    靶机DC-2 rbash绕过+git提权
    单表查询
    数据库和表的基本操作(二)
    数据库和表的基本操作(一)
    MySQL的约束
    bugku-misc 9-16
    Linux基础命令
    时间-i春秋
  • 原文地址:https://www.cnblogs.com/autotest/p/3483981.html
Copyright © 2020-2023  润新知