Simpel Posted August 10, 2014 Share Posted August 10, 2014 (edited) Hi,I'm running a script that is filling XML-childs step by step. It looks like:Func _AddXML($XMLvF,$XMLtF,$bDirection) $zone = _Date_Time_GetTimeZoneInformation() If $bDirection = 2 Then $deviceID = $deviceIDdown Else $deviceID = $deviceIDup EndIf Dim $Keys[2] = ["ID","categoryID"] Dim $Values[2] $Values[0] = $deviceID $Values[1] = $categoryID _XMLCreateChildWAttr ("//data", "device", $Keys, $Values) Dim $Keys[4] = ["value","timestamp","TZ","scale_unit"] Dim $Values[4] $XMLvF = Number($XMLvF) $Values[0] = $XMLvF $Values[1] = $XMLtF If $zone[0] = "2" Then $Values[2] = "CEST" Else $Values[2] = "CET" EndIf $Values[3] = "MBit/s" _XMLCreateChildWAttr ("//device", "measurement", $Keys, $Values) EndFuncFirst round everything is ok. But second round there should be another device ID="199" and the measurement value should be written to this child. But it's writing in both device childs:<?xml version="1.0" encoding="UTF-8" ?> - <vd-In CreatedByAppVersion="1.0.2.13" XMLAPIVersion="1.1"> - <data> - <device ID="175" categoryID="3"> <measurement value="479.72" timestamp="2014-08-10T18:34:58" TZ="CEST" scale_unit="MBit/s" /> <measurement value="481.78" timestamp="2014-08-10T18:35:04" TZ="CEST" scale_unit="MBit/s" /> </device> - <device ID="199" categoryID="3"> <measurement value="481.78" timestamp="2014-08-10T18:35:04" TZ="CEST" scale_unit="MBit/s" /> </device> </data> </vd-In>The difference is that $bDirection is first 1 and second round 2.Ideas? Regards, Simpel Edited September 25, 2015 by Simpel solved SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Solution jdelaney Posted August 11, 2014 Solution Share Posted August 11, 2014 I'm not familiar with the UDF, but it's probably adding to all matches. Try narrowing it down to your id: _XMLCreateChildWAttr ("//device[@id=199]", "measurement", $Keys, $Values) Or, you can not use the udf (you can create your own function from this example: $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.LoadXML("<vd-In CreatedByAppVersion=""1.0.2.13"" XMLAPIVersion=""1.1""><data /></vd-In>") $oData = $oXml.SelectSingleNode("//data") $oDevice = $oXML.CreateElement("device") $oDevice.SetAttribute("ID",175) $oDevice.SetAttribute("CategoryID",3) $oMeasurement = $oXML.CreateElement("measurement") $oMeasurement.SetAttribute("value",479.72) $oMeasurement.SetAttribute("timestamp","2014-08-10T18:34:58") $oMeasurement.SetAttribute("scale_unit","MBit/s") $oMeasurement.SetAttribute("TZ","CEST") $oDevice.appendChild($oMeasurement) $oData.appendChild($oDevice) $oDevice = $oXML.CreateElement("device") $oDevice.SetAttribute("ID",175) $oDevice.SetAttribute("CategoryID",3) $oMeasurement = $oXML.CreateElement("measurement") $oMeasurement.SetAttribute("value",481.78) $oMeasurement.SetAttribute("timestamp","2014-08-10T18:35:04") $oMeasurement.SetAttribute("scale_unit","MBit/s") $oMeasurement.SetAttribute("TZ","CEST") $oDevice.appendChild($oMeasurement) $oData.appendChild($oDevice) ConsoleWrite($oXml.xml) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Simpel Posted August 12, 2014 Author Share Posted August 12, 2014 (edited) Try narrowing it down to your id: _XMLCreateChildWAttr ("//device[@id=" & $deviceID & "]", "measurement", $Keys, $Values) That's solving my problem. Thank you. Regards, Simpel Edited August 12, 2014 by Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now