mports System.Xml
Dim ShipXMLDocument As XmlDocument = New XmlDocument()
ShipXMLDocument.Load(FilePath)
Dim objNodeList = Nothing
objNodeList = ShipXMLDocument.DocumentElement.SelectNodes("//ShipShipment/DataArea/Shipment/Header/Parties/Party")
This makes no sense. Why not just set it's value in the first line?
If objNodeList.Count > 0 Then
For i = 0 To objNodeList.Count - 1
I doubt that count - 1 is correct. Also, you can do a foreach on the node list instead of having to look them up by index
If objNodeList.Item(i).FirstChild.InnerText <> "SHIPPER" Then
For ChildNode = 0 To objNodeList.Item(i).ChildNodes.Count - 1
If objNodeList.Item(i).ChildNodes.Item(ChildNode).Name = "Name" Then
I am fairly certain you could use an xpath to exclude 'SHIPPER' as a value.
objNodeList.Item(i).ChildNodes.Item(ChildNode).InnerText = "Tester McTestingstein"
ElseIf objNodeList.Item(i).ChildNodes.Item(ChildNode).Name = "EmailAddress" Then
This sort of code turns into spaghetti fast. Use a switch statement to operate no different nodes. Also, if you're looking at node names, not values, you would do better having two node collections at this level, one for each node you want to work with
objNodeList.Item(i).ChildNodes.Item(ChildNode).InnerText = "Testing@Testing.com"
End If
Next
End If
Next
End If
ShipXMLDocument.Save(FilePath)
If this is blowing up, I would try storing the XML in a string and using File.SaveAllText to save it and see if that works