2014-05-13 1 views
0

저는 Jenkins 및 RedGate DeploymentManager2를 사용하여 SQL Server Analysis Services를위한 배포 솔루션을 개발 중입니다.PowerShell의 XML 파서의 일관성없는 (?) 동작을 확인하십시오.

주어진 서버에서 XMLA 파일을 실행하는 코드가 있습니다 : (이 스 니펫은 단순화되었으므로 실제 솔루션에서는 더 많은 오류 검사가 있지만이 점만 이해하면됩니다)

<return xmlns="urn:schemas-microsoft-com:xml-analysis"> 
     <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"> 
     <Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /> 
     <Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"> 
      <Warning WarningCode="-1055653884" Description="Errors in the metadata manager. ... bla.. bla.. bla.." Source="Microsoft SQL Server 2012 Analysis Services" HelpFile="" /> 
     </Messages> 
     </root> 
    </return> 

: 여기

Import-Module SQLPS Import-Module sqlascmdlets [string]$xmlaPath = "D:\Test\process.xmla"; [string]$asServer = "MyServer" [string]$asCmdResultPath = "D:\Test\test.xml" [string]$asCmdTracePath = "D:\Test\test.astrace" Invoke-ASCmd -InputFile "$xmlaPath" -Server "$asServer" -TraceFile "$asCmdTracePath" -ErrorAction Stop | Out-File "$asCmdResultPath" 

합니다 (Process 명령이 존재하지 않는 데이터베이스 이름을 제공함으로써 생성되는) 예시적인 에러 출력 내 목표는이 출력에 오류가 있는지 확인하는 것입니다.

이 내 현재 코드는 다음을 달성하기 위해 (그리고 잘 작동 - 또한 더 나은 이해를 위해 간체) :

# Processing result XML generated by Invoke-ASCmd 
[xml]$resultXml = [xml](Get-Content $asCmdResultPath) 

[System.Xml.XmlNamespaceManager]$nsmgr = $resultXml.NameTable 

$nsmgr.AddNamespace($null, 'urn:schemas-microsoft-com:xml-analysis') 
$nsmgr.AddNamespace('ase', 'urn:schemas-microsoft-com:xml-analysis:empty') 
$nsmgr.AddNamespace('asex', 'urn:schemas-microsoft-com:xml-analysis:exception') 
$nsmgr.AddNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/') 

$exceptionNodes = $resultXml.SelectNodes("//asex:Exception", $nsmgr) 

Write-Host $exceptionNodes.Count # Output: 1 

내가 언급 한 바와 같이,이 잘 작동하지만 ...

위의 XML 파일을 처리하려고 할 때 다음과 같은 네임 스페이스를 사용하지 않고 시도했습니다.

객체처럼 액세스를 사용하여 63,210

: 그것은와 네임 스페이스를 사용하지 않고 노드를 찾을 수 있습니다

$x = $resultXml."return".root.Exception 
Write-Host "Object: $($x | Format-Table | Out-String)" 

. 위의 코드에 대한

출력 : PowerShell에서이 네임 스페이스와 XML과 함께 작동 할 때 너무 일관성이 왜

xmlns 
----- 
urn:schemas-microsoft-com:xml-analysis:exception 

?

- 또는 -

내가 네임 스페이스를 사용하지 않고 주어진 예제 XML 작업을 시도 할 때, 내가 잘못 했습니까?

모든 정보를 제공해드립니다.

오류 처리에 대한

더 많은 정보 XMLA 실행하는 동안 : Handling Errors and Warnings (XMLA)

환경

  • 윈도우 7 64 비트
  • 파워 쉘 2.0 SQL 서버 2012
  • (+ AS)

답변

1

XPath 표현식 //Exception은 이름 공간이없는 요소 만 일치시킵니다. 따라서 요소를 전혀 반환하지 않을 것으로 예상됩니다.//*[local-name()='Exception'을 사용하여이 문제를 해결할 수 있습니다 (구문은 약간 꺼져 있지만 아이디어는 얻을 수 있습니다).

속성에 액세스 할 수있는 이유는 PowerShell이 ​​네임 스페이스에 관계없이 유용하게 이러한 속성을 만들기 때문입니다. 이는 XML 파일을 대화식으로 처리 할 때 유용합니다. 그러나 네임 스페이스를 섞어서 같은 이름의 요소를 다른 네임 스페이스로 사용하면 구별 할 수 없습니다.

+0

고맙습니다. – Pred

관련 문제