Search the Community
Showing results for tags 'xml delete'.
-
Can anyone assist with creating/modify/delete XML Nodes/Child Nodes? Have a document for example: <ConfigData> <parameter> <name>Setting One</name> <value>10</value> </parameter> <parameter> <name>IPAddress</name> <value>192.168.1.1</value> </parameter> <parameter> <name>Setting One</name> <value>200</value> </parameter> <parameter> <name>Setting Three</name> <value>300</value> </parameter> </ConfigData> Would like to add another node parameter/name, parameter/value, but unsure how to, when there are multiple instances with the same tagname for example, would like to add the following if the nodes do not already exist: <parameter> <name>UserPreferredLanguage</name> <value>English</value> </parameter> Currently using the following to check and delete/modify existing nodes, was thinking of placing the name and value into a 2d array and then using a true/false in a 3rd column to return if the setting was found and modified or not, so I can decide whether I need to create the nodes or not, but I'm hoping there is a simpler way.\ Any assistance would be much appreciated. PS: Have also written this with the XML Dom Wrapper UDF but still unsure how to proceed with checking nodes and creating them if they're missing, also couldn't find a function to delete a full node + parent using selectNodes, hence the custom __XML_DeleteNode function. Thanks Local $sXMLDocPath = @ScriptDir & "\XMLDoc.xml" Local $oXMLDoc = ObjCreate("MSXML2.DOMDocument") $oXMLDoc.validateOnParse = False $oXMLDoc.load($sXMLDocPath) Local $oXMLNodes = $oXMLDoc.selectNodes("ConfigData/parameter") If IsObj($oXMLNodes) Then For $oXMLNode In $oXMLNodes If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting One" Then If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 10 EndIf If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "IPAddress" Then __XML_DeleteNode($oXMLNode) EndIf If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting Two" Then If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 20 EndIf If $oXMLNode.childNodes.item(0).tagName = "Name" And $oXMLNode.childNodes.item(0).Text = "Setting Three" Then If $oXMLNode.childNodes.item(1).tagName = "Value" Then $oXMLNode.childNodes.item(1).Text = 30 EndIf Next EndIf $oXMLDoc.Save ($sXMLDocPath) Func __XML_DeleteNode($_oNode_Enum) If $_oNode_Enum.hasChildNodes Then For $_oNode_Enum_Child In $_oNode_Enum.childNodes If $_oNode_Enum_Child.nodeType = $XML_NODE_TEXT Then If StringStripWS($_oNode_Enum_Child.text, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) = "" Then $_oNode_Enum.removeChild($_oNode_Enum_Child) EndIf EndIf Next EndIf $_oNode_Enum.parentNode.removeChild($_oNode_Enum) EndFunc
- 5 replies
-
- xml
- xml create
-
(and 2 more)
Tagged with: