ok - I have one more question, and this pushes me over the finish line on this project. Please see attached. As you can see there are many places where I am injecting an Element into an existing node:
$e = $PY.CreateElement("ORIGREF")
$e.set_InnerText($InvOrigRef.Node.InnerText.Trim())
$node.AppendChild($e)
I am doing this type of operation while I am in an existing node, which I have set with $PY.SelectNodes
I have a new requirement in which I would have to inject some Elements and set InnerText on a node I will be creating in flight. Is that possible? If so - how would it look?
Something along these lines?
$newpayline = $PY.CreateElement(“PAYLINE”)
$PY.AppendChild($newpayline)
–Which would just add the node at the root of the file - I think $PY would already be at the root, correct? and therefore I am adding a new node at the root, or is there something I have to do before this to set $PY back to the root?
Now
$newelement = $newpayline.CreateElement(“ORIGREF”)
$newelement.set_InnerText($InvOrigRef.Node.InnerText.Trim())
$newpayline.AppendChild($newelement)
And so forth…
In reviewing the file, the business case is that in the PAYHEADER under USERAREA there are one or more DATASTREAM.EXTCHARGEDISTRIBUTION entries that I need to transform into PAYLINES and append them to the file. Not every field is needed to be cloned from the existing PAYLINE Nodes, I just have to create a new PAYLINE and add the elements I am going to need to work with later on.
So inside of a foreach loop on those PAYHEADER EXTCHARGEDISTRIBUTIONs I would perform the operations to grab all the variables I need (which I have already figured out), and then append a new PAYLINE node and inject the variable values in as necessary in ELEMENTS under the new PAYLINE. So in reference to the XML example file I had, the result would be that 2 PAYLINES are added, and they contain the variable values I grabbed from each EXTCHARGEDISTRIBUTION on the PAYHEADER
Again - is this possible? I am beginning to realize that almost anything is possible with PowerShell, so I hoping this is not a big deal. Do I generally have the right idea, or am I in a different territory when I want to start adding nodes at the root?
Thank you again in advance for all of your assistance.