dongya2029 2019-08-08 20:15
浏览 71

删除每个循环结束时在循环内创建的XML元素

I have a script that scans every item laptop in my Snipe IT inventory, compares it against that same instance in my Jamf Pro server, and for any fields that do not match, it creates an XML and sends that XML over to Jamf. What I need is for the XML to have all of its elements "wiped" after sending the payload over. I have tried countless --- countless --- ways to make this happen, but even when I "print" the supposedly "wiped" payload at the end of the script and confirm that the element was removed, it still appears the next time around when I inspect the payload that was sent to Jamf. If I have three laptops with info that gets sent over, I get three fields. Four, I get four. And so on. I really need to figure out how to reset this XML to make this script cleaner.

Here is where I am creating the XML, if the information does not match.

// let's compare the DEVICE ASSIGNMENT across our two systems, knowing that itassets is our SOT
if ($jamf_assignment !== $itassets_assignment) {
    echo "
" . "ALERT: The device assignment is not in sync across our systems!" . "
";
    if (!isset($location)) {
    $location = $jamf_xml->createElement('location');
    $location->appendChild($jamf_xml->createElement('real_name',$itassets_assignment));
    $process_xml = 1;
    } else {
        $location->appendChild($jamf_xml->createElement('real_name',$itassets_assignment));
        $process_xml = 1;
    }
} else {
     echo "
" . "DEVICE ASSIGNMENT CHECKS OUT! ALL GOOD HERE!" . "
";
}

And here is where I am turning it into a payload, about to be sent.

if (!empty($location)) {
    $computer->appendChild($location);
}
$jamf_xml->appendChild($computer);
$jamf_payload = $jamf_xml->saveXML();

And finally here is where I am trying to reset that XML, and start fresh with the next loop.

// and finally let's destroy the XML file
if (!empty($general)) {
    $computer->removeChild($general);
}
if (!empty($location)) {
    $computer->removeChild($location);
}
$jamf_xml->appendChild($computer);
$jamf_payload = $jamf_xml->saveXML();
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!