<? //config------------------------------------- $filename = "a.xml"; $page = $_GET["page"]; $workstationid = $_POST["workstationid"]; $workstationgetid = $_GET["workstationgetid"]; $workstationname = $_POST["workstationname"]; $workstationip = $_POST["workstationip"]; $workstationsfdcmode = $_POST["workstationsfdcmode"]; $workstationport = $_POST["workstationport"]; $workstationDC = $_POST["workstationDC"]; //end config ------------------------------- echo $workstationgetid; if($page=='add') { $checkname = 0; $xml = simplexml_load_file($filename); foreach($xml->children() as $node){ $arr = $node->attributes(); if ($arr['name']==$workstationname){ $checkname = 1; } } if ($checkname <> 1){ $xml = simplexml_load_file($filename); $sxe = new SimpleXMLElement($xml->asXML()); $workstation = $sxe->addChild("workstation"); $workstation->addAttribute("name",$workstationname); $workstation->addChild("ip", $workstationip); $workstation->addChild("sfdcmode", $workstationsfdcmode); $workstation->addChild("port", $workstationport); $workstation->addChild("dc", $workstationDC); $sxe->asXML($filename); echo "save Complete"; } } if ($page=='del' && $workstationgetid <> null){ $file = $filename; $fp = fopen($file, "rb") or die("cannot open file"); $str = fread($fp, filesize($file)); $xml = new DOMDocument(); $xml->formatOutput = true; $xml->preserveWhiteSpace = false; $xml->loadXML($str) or die("Error"); // original echo "<xmp>OLD:\n". $xml->saveXML() ."</xmp>"; // get document element $root = $xml->documentElement; $fnode = $root; //get a node $ori = $fnode->childNodes->item($workstationgetid); // remove $fnode->removeChild($ori); echo "<xmp>NEW:\n". $xml->saveXML() ."</xmp>"; /* $file = $filename; $fp = fopen($file, "rb") or die("cannot open file"); $str = fread($fp, filesize($file)); $xml = new DOMDocument(); $xml->formatOutput = true; $xml->preserveWhiteSpace = false; $xml->loadXML($str) or die("Error"); //$xml->saveXML() ; //$root = $xml->documentElement; $fnode = $xml->documentElement; $ori = $fnode->childNodes->item("1"); $fnode->removeChild($ori); $xml->saveXML(); //$xml->asXML($filename); */ echo "Del Complete"; } ?> <html> <head><title>Emulator Client Control</title></head> <body> <center> <table border=1> <tr> <th width="20"></th> <th width="20">No.</th> <th width="200">Name</th> <th width="120">IP</th> <th width="100">SFDC MODE</th> <th width="100">Port</th> <th width="100">DC</th> </tr> <? $xml = simplexml_load_file($filename); $i=0; foreach($xml->children() as $node){ $arr = $node->attributes();?> <tr> <td align="center"><a href="index.php?page=del&workstationgetid=<? echo $i; ?>">Del</a></td> <td align="center"><?echo $i+1;?></td> <td><? echo $arr['name']."<br>"; ?></td> <? foreach($xml->workstation[$i]->children() as $child) { ?> <td align="center"><? echo $child; ?></td> <? } ?> </tr> <? $i++; ?> </tr> <? }?> </table> <form name="input" action="index.php" method="POST"> Workstation Name : <input type="text" name="workstationname" /><br> Workstation IP : <input type="text" name="workstationip" value="192.168.1." /><br> Workstation SFDC Mode : <input type="text" name="workstationsfdcmode" value="SFDC3"/><br> Workstation Port : <input type="text" name="workstationport" value="18000"/><br> Workstation DC : <input type="text" name="workstationDC" /> <br> <input type="submit" value="add" name="page" /> </form> </center> </body> </html>
<?xml version="1.0"?> <workstations> <workstation name="Demo A"> <ip>192.168.1.2</ip> <sfdcmode>SFDC3</sfdcmode> <port>18000</port> <dc>191</dc> </workstation> <workstation name="Demo B"> <ip>192.168.1.224</ip> <sfdcmode>SFDC3</sfdcmode> <port>18000</port> <dc>191</dc> </workstation> </workstations>
$xml->saveXML(); $xml->save('a.xml');
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง