Open an indivdual XML File for Editing

by Oct 14, 2011

Hello,

I've got the following Powershellscript:

Clear-Host
[xml] $Quelle = (get-content C:ProjekteNewRateTablesRatetablesphoenix-USA.xml)
$RV = Read-Host -Prompt "Bitte geben Sie die Versionsnummer ein: "
$RR = Read-Host -Prompt "Bitte geben Sie die Revisionsnummer ein: "
echo $RR
echo $RV
$Quelle.RootRateDB.Header.GetAttribute("RateRevision")
$Quelle.RootRateDB.Header.GetAttribute("RateVersion")
$Quelle.RootRateDB.Header.SetAttribute("RateRevision", "$RR")
$Quelle.RootRateDB.Header.SetAttribute("RateVersion", "$RV")
$Quelle.Save("c:ProjekteNewRateTablesRatetablesphoenix-USA.xml")

Everything works fine. Now I want to change the hardcoded filepath to a user selectable. So I wrote the following lines and put them infront of all the other line:

$Quelle=""
$Dlg=""
$Antw=0
function Dateiauswahl([System.String]$strFilter="XML Dateien (*.xml)|*.xml")
{
$Dlg=New-Object("System.Windows.Forms.OpenFileDialog")
$Dlg.Filter=$strFilter
$Antw=$Dlg.ShowDialog()
if ($Antw -eq 1)
{
return $Dlg.Filename
}
}
# $Quelle= DateiAuswahl
echo "Die Datei $Quelle wurde gewaehlt!"
# $Quelle = [xml] (get-content DateiAuswahl)

But I get the following error:
Der Wert "" kann nicht in den Typ "System.Xml.XmlDocument" konvertiert werden. Fehler: "Das Stammelement ist nicht vorhanden."Bei C:Userstheinemann.INF99DocumentsDateiinhalt

ändern.ps1:2 Zeichen:8
+ $Quelle <<<< =""
+ CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
+ FullyQualifiedErrorId : RuntimeException
How do I had to change the source, that the user can select the file, that had to be changed.

Thanks Regards
Thomas