I am new to PowerShell and need to understand why this does not work:
This first example works the way I want.
Function Get-FileName($initialDirectory){
[System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = “All files (*.*)| *.*”
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-FileName
$Document = [xml]''
Write-Host "Please select the Actual file."
$ActualFile = Get-FileName -initialDirectory “$HOME\Downloads” # This function gets the file name of the file you want to create an object.
[ xml ]$Document = Get-Content $ActualFile
Foreach($TechRcrdId in $Document.BizData.Pyld.Document.SctiesFincgRptgTxRpt.TradData.Rpt.Err.TechRcrdId){
Write-Host "TechRcrdId :" $TechRcrdId
}
This does not do what I want but I want to use a variable for the path.
$Document = [xml]''
Write-Host "Please select the Actual file."
$ActualFile = Get-FileName -initialDirectory “$HOME\Downloads” # This function gets the file name of the file you want to create an object.
[ xml ]$Document = Get-Content $ActualFile
$NodePath = "BizData.Pyld.Document.SctiesFincgRptgTxRpt.TradData.Rpt.Err.TechRcrdId"
Foreach($TechRcrdId in $Document.$NodePath){
Write-Host "TechRcrdId :" $TechRcrdId
}
Before we proceed … could you please go back, edit your question once again and fix the formatting of your code?
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
That google search shows how to split out each node in the chain. I am looking for a way to use a variable to replace the dot path. Also I don’t really have namespaces in the XML.
Just starting out with PowerShell so I am taking baby steps.
What I want to do is better a compare tool built in PowerShell that does not order the repeatable field (could be 1 or Many) so the compare fails.
It might be better for me to build my own compare tool that compares true XML as the current one just breaks up the XML the compares based on the trade strings. I am trying to find a way to order the XML so the strings will compare and not give false positives.
My xml paths will be many as my documents can have hundreds of trades so I think making my Xpath a variable is the best way to go.