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 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 有没有帮写代码做实验仿真的
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥30 vmware exsi重置后登不上
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题