2012-11-04 5 views
3

두 개의 XML 구성 파일이 있습니다. 두 파일의 구조 만 비교하고 차이점을 표시해야합니다. 참고 : 비교할 때 xml 노드 내의 값은 무시해야합니다.Powershell을 사용하여 XML 구조를 비교하십시오.

예 : 결과는 두 개의 XML 파일의 차이해야

XML 1 
---- 
<recipe> 
    <ingredients> 
     <ingredient1></ingredient1><ingredient2></ingredient2> 
    </ingredients> 
    <description></description> 
</recipe> 

XML 2 
----- 
<recipe> 
    <ingredients> 
    <ingredient1></ingredient1> 
    </ingredients> 
    <description></description> 
    <images></images> 
</recipe> 

.

xml1 <ingredient2> 
xml2 <images> 

도움 주시면 감사하겠습니다. 내가 가지고 올 수

답변

7

가장 빠른 솔루션입니다 :

[xml]$xml1 = @" 
<recipe> 
    <ingredients> 
     <ingredient1> 
     </ingredient1> 
     <ingredient2> 
     </ingredient2> 
    </ingredients> 
    <description></description> 
</recipe> 
"@ 

[xml]$xml2 = @" 
<recipe> 
    <ingredients> 
    <ingredient1>dada</ingredient1> 
    </ingredients> 
    <description>dadad</description> 
    <images></images> 
</recipe> 
"@ 

$docDiffs=Compare-Object ($xml1.SelectNodes("//*") | Select-Object -Expand Name) ($xml2.SelectNodes("//*") | Select-Object -Expand Name) 

$docDiffs 

당신은 당신이 필요로하는 정확한 형식화하는을 얻기 위해 약간의 작업을 수행해야하지만 주요 작업이 완료되었다. 이 기능을 향상 시키려면 Select-XML을 사용하십시오.

+0

위대한 작품! 감사. – jack

+0

도움이 되니 기쁩니다. –

관련 문제