Powershell script for XML comparision -
i trying compare web.config file production non production using powershell script. able generate code can compare upto 1 level beyond didn't find on internet compare , update xml file multilevel deep node structure. below code works upto first level in file not beyond. there way can compare 2 file , update without hard coding node element? below code works upto 1 level.
$src_web_config = "c:\users\live\web.config" $dst_web_config = "c:\users\int\web.config" # creating xml objects live , integration $src_xml = new-object -typename xml $dst_xml = new-object -typename xml $src_xml.load($src_web_config) $dst_xml.load($dst_web_config) # top nodes $src_top_node = $src_xml.documentelement.name $dst_top_node = $dst_xml.documentelement.name function add_node($add_node) { write-host "node", $add_node.name, "doesn't exist" $node = $dst_xml.importnode($add_node, $true) $dst_xml.$dst_top_node.appendchild($node) $dst_xml.save($dst_web_config) } if ($src_top_node -eq $dst_top_node) { if ($src_xml.$src_top_node.haschildnodes) { $src_xml.$src_top_node.childnodes | % { if ($dst_xml.$dst_top_node.childnodes.name -contains $_.name) { if ($_.haschildnodes) { #nothing can find } } else { add_node($_) } } } } regards, vj
microsoft has xml diff , patch tool can use in .net application. microsoft provides sample gui tool written in c# uses library. can download gui source code installer here.
i don't have particular advice on using xml diff library powershell. using .net libraries powershell whole other topic, can find information on online. if not committed powershell, perhaps use c# or vb.net instead, in gui tool. if don't need write own script automate process, can use gui tool diff xml files on as-needed basis.
Comments
Post a Comment