저는 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)
고맙습니다. – Pred