I have an XMl which I'd like to expand.
- I want to select the 2. "Step" Node- > copy -> Change -Number- | -Name- and some inner-Text strings
- I want to select the 2. "Transition" Node -> copy -> Change -Number- | -Name- and some inner-Text strings
- I want to select the 2. "Connection" Node -> copy -> Change some inner-Text strings
- I want to select the penultimate "Connection" copy -> Change some inner-Text strings
Here are my XML (without the end-tags):
Here are the Code that work fine in an other job:
$OPN_in ='C:\OPN\OPNOUT.xml'
$OPN_Out='C:\OPN\imp\OPNIMP.xml'
# xml Objekt erstellen
$xml = New-Object XML
# xml laden
$xml.Load($OPN_in)
# Abfrage des ersten 'SW.Blocks.CompileUnit' Knotens
$Bsp_NW = $xml.SelectSingleNode("//SW.Blocks.CompileUnit")
# abbrechen wenn kein Knoten gefunden wurde.
if (!$Bsp_NW){
throw "Error, 'SW.Blocks.CompileUnit' Node not found!"
exit 1
}
# erstelle eine Kopie des Knotens im Speicher
$NEU_NW = $Bsp_NW.Clone()
$NEU_NW.innerxml = $NEU_NW.innerxml -replace ("'Start'" -replace "'"),("'NEXT'" -replace "'")
# id anpassen
$NEU_NW.Id = (100*$z).ToString()
# hänge den kopierten Knoten im selben Parent wie vom Original wieder ins XML ein
$Bsp_NW.ParentNode.InsertAfter($NEU_NW,$Bsp_NW)
#Basisdatenändern
$xml.Document.'SW.Blocks.FC'.AttributeList.Name ='OPN_NEW'
$xml.Document.'SW.Blocks.FC'.AttributeList.Number = [String]($xml.Document.'SW.Blocks.FC'.AttributeList.Number+'00')
# speichere das geänderte xml unter neuem Namen
$xml.Save($OPN_Out)
#>
What not work is:
$Bsp_NW = $xml.SelectSingleNode("//Steps")
thanks for support.

$xml = [xml] "<Document><SW.Blocks.FB><SW.Blocks.CompileUnit><AttributeList><NetworkSource><PreOperations><Sequence><Steps><Step /><Step /></Steps></Sequence></PreOperations></NetworkSource></AttributeList></SW.Blocks.CompileUnit></SW.Blocks.FB></Document>"; $xml.SelectSIngleNode("//Steps")so you might need to provide a larger sample of your failig code - e.g. how to you initialise$xml? And can you post as text (not a picture) the xml document you're loading?