Jump to content

[Solved] _XMLCreateChildWAttr is adding to all childs matching


 Share

Go to solution Solved by jdelaney,

Recommended Posts

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)
EndFunc

First 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 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)

   88x31.png  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

  • Solution

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

 

Try narrowing it down to your id:

_XMLCreateChildWAttr ("//device[@id=" & $deviceID & "]", "measurement", $Keys, $Values)

That's solving my problem. Thank you.

Regards, Simpel

Edited 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)

   88x31.png  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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...