Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

XML Comparision using powershell

$
0
0

Hi Friends,

I am trying to compare two xml files one is from Production and other one is from Non Production. I have to modify non production file to incorporate production changes.  I have created a function and calling it recursively to reach deep inside xml nodes. Here in the code, new path is not getting formed properly at line $new_fullpath = $fullpath + "." + $_ .

Everytime null value is getting assigned to $new_fullpath variable. It looks like I am using string operations on xml objects which is creating problems. Can anyone suggest better way of solving this problem?

 

# Define Function

function compare_nodes($node, $fullpath)

{

if ($src_xml.$fullpath.name -eq $dst_xml.$fullpath.name)

{

            if ($src_xml.$fullpath.HasChildNodes)

{

$src_xml.$fullpath.childnodes.name | % {

#write-host "Before new path " $fullpath

$new_fullpath = $fullpath + "." + $_

write-host "New full path is " $new_fullpath

compare_nodes $_ $new_fullpath

}

}

else

{

write-host "No child found for " $src_xml.$fullpath

return

}

}

else

{

write-host $src_xml.$fullpath.$node.name " not found in destination file"

$add_node = $dst_xml.ImportNode($src_xml.$fullpath.$node, $true)

write-host $fullpath

$dst_xml.selectsinglenode("//$fullpath").appendchild($add_node)

}

}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles