0

I have an XMl which I'd like to expand.

  1. I want to select the 2. "Step" Node- > copy -> Change -Number- | -Name- and some inner-Text strings
  2. I want to select the 2. "Transition" Node -> copy -> Change -Number- | -Name- and some inner-Text strings
  3. I want to select the 2. "Connection" Node -> copy -> Change some inner-Text strings
  4. I want to select the penultimate "Connection" copy -> Change some inner-Text strings

Here are my XML (without the end-tags):

XML

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.

1
  • What "doesn't work"? Do you get an error, or just not returning the value you expect? It seems to work here with this: $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? Commented Sep 28, 2023 at 9:00

1 Answer 1

0

Now It's working with:

# Abfrage des ersten 'SW.Blocks.CompileUnit' Knotens
$Bsp_NW = $xml.SelectSingleNode("//SW.Blocks.CompileUnit")

$Bsp_NW = $xml.SelectSingleNode("//Steps")

$NEW_Step = $Bsp_NW.step[1].Clone()
$NEW_Step.Number

I'm confusing...

But Maybe you can give me a tipp How to select a step by using die "number" attribute ?

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.