php - Save XML file without Declaration - with specific address -


i trying find way save xml file once edited, without including declaration. need able set address. saving on original xml, , saving on temp location 1 (duplicate of original javascript access, original in local file).

so tried $dom->savexml($xml->documentelement); comes out save errors. php page gets form data , saves loaded xml, saves , copy (down bottom of below code)

<?php //header('location: ../index.php' );  $dom = new domdocument(); $dom->preservewhitespace = false; $dom->formatoutput = true; $dom->load("../data/fileloc.xml");  $fileurltag = $dom->getelementsbytagname('fileurl')->item(0); $filename = $fileurltag->getattribute('filename'); $fileaddress = $fileurltag->getattribute('address'); $fileurl = $fileaddress.$filename;   if(isset($_request['ok'])){     $xml = new domdocument();     $xml->preservewhitespace = false;     $xml->formatoutput = true;     $xml->load($fileurl);      //checks if objects tag exists     $roottag = $xml->getelementsbytagname("objects")->item(0);      //if objects tag doesnt exist, creates , unique id     if($xml->getelementsbytagname("objects")->length == 0){         $roottag = $xml->createelement("objects");         $alph = "0123456789abcdef";         $ranstr = '';         for($i=0;$i<32;$i++){             if($i==8 || $i==12 || $i==16 || $i==20){                 $ranstr .= "-";             }             $pos = rand(0,35);             $ranstr .= $alph[rand(0, strlen($alph)-1)];             };         $randid = "{".$ranstr."}";         $roottag->setattribute("overlayid",$randid);          $objdoctag = $xml->getelementsbytagname("objectsdoc")->item(0);          if($objdoctag->getattribute("version")->length == 0){                 $objdoctag->setattribute("version","1.0");         };          $objdoctag->appendchild($roottag);     };         //used set id on layer tag - gets value objects->overlayid attribute     $getid = $roottag->getattribute('overlayid');     //used set id on object tag     $numobj = $xml->getelementsbytagname('object')->length;      //commstag determines colours pen , brush tags     $commstag = $xml->createelement("comms",$_request["comms"]);       //convert deg radians     $lat = $_request['lat'];     $long = $_request['long'];     $latrad = ($lat*6.28318)/360;     $longrad = ($long*6.28318)/360;     if($_request['comms']=='good'){         $color = array(255,0,255,0);     };     if($_request['comms']=='bad'){         $color = array(255,0,255,255);     };     if($_request['comms']=='none'){         $color = array(255,0,0,255);     };      //create object , set object attributes     $objecttag = $xml->createelement("object");         $objecttag->setattribute("id",($numobj+1000));         $objecttag->setattribute("parent",$_request['level']);         $objecttag->setattribute("visibile","1");         $objecttag->setattribute("type","mapdraw_object");         $graphictag = $xml->createelement("graphic");             $graphictag->setattribute('alwaysshowname','1');             $graphictag->setattribute('font',"calibri");             $graphictag->setattribute('name',strtoupper($_request["callsign"]));             $graphictag->setattribute('textcolor',"0");             $graphictag->setattribute('textposition',6);             $graphictag->setattribute('version',"1.0");             $graphictag->setattribute('visible',1);             $graphictag->setattribute('size',12);                     $layertag = $xml->createelement("layer");                         $layertag->setattribute('id',$getid);                     $graphicprimtag = $xml->createelement("graphicprimitive");                         $graphicprimtag->setattribute('type','circlesector');                         $graphicprimtag->setattribute('version','1.0');                             $pentag = $xml->createelement('pen');                                 $pentag->setattribute('a',255);                                 $pentag->setattribute('b',255);                                 $pentag->setattribute('g',255);                                 $pentag->setattribute('r',255);                                 $pentag->setattribute('type',0);                                 $pentag->setattribute('size',4);                             $brushtag = $xml->createelement('brush');                                 $brushtag->setattribute('a',$color[0]);                                 $brushtag->setattribute('b',$color[1]);                                 $brushtag->setattribute('fillstyle',10);                                 $brushtag->setattribute('g',$color[2]);                                 $brushtag->setattribute('r',$color[3]);                             $circletag = $xml->createelement('circlesector');                                 $circletag->setattribute('radius',500);                             $fonttag = $xml->createelement('font');                                 $fonttag->setattribute('name','calibri');                                 $fonttag->setattribute('size','15');                     $coordstag = $xml->createelement("coordinates");                         $coordstag->setattribute("absolute","1");                         $coordstag->setattribute('system','wgs84');                             $refcoordtag = $xml->createelement("refcoordinate");                                 $refcoordtag->setattribute('rotation',0);                                 $refcoordtag->setattribute('x',$latrad);                                 $refcoordtag->setattribute('y',$longrad);                                 $refcoordtag->setattribute('z','0');                             $coordtag = $xml->createelement("coordinate");                                 $coordtag->setattribute('x',$latrad);                                 $coordtag->setattribute('y',$longrad);                                 $coordtag->setattribute('z','0');                                 $coordtag->setattribute('index','0');         $accesstag = $xml->createelement("accessrights");             $accesstag->setattribute('editable',0);             $accesstag->setattribute('moveable',0);             $accesstag->setattribute('selectable',1);       //append refcoordinate , coordinate coordinates     $coordstag->appendchild($refcoordtag);     $coordstag->appendchild($coordtag);     //append pen, brush, circleselector , font graphicprimitive     $graphicprimtag->appendchild($pentag);     $graphicprimtag->appendchild($brushtag);     $graphicprimtag->appendchild($circletag);     $graphicprimtag->appendchild($fonttag);     //append layer, graphicprimitive, coordinates graphic     $graphictag->appendchild($layertag);     $graphictag->appendchild($graphicprimtag);     $graphictag->appendchild($coordstag);     //append graphic object     $objecttag->appendchild($graphictag);     $objecttag->appendchild($accesstag);     //append object objects     $roottag->appendchild($objecttag);      echo($fileurl);     $xml->save($fileurl);     $xml->save("..temp/".$filename);     exit(); }; 

i tried running these (first 1 save location $xml loaded assume? , second 1 temp folder javascript - second 1 can have declaration).

$xml->savexml($xml->documentelement); $xml->save("..temp/".$filename); 

but error below

warning: domdocument::save(..temp/bms_overlays.xml) [domdocument.save]: failed open stream: no such file or directory in d:\programs\server2go\htdocs\analyst\scripts\createcontent.php on line 152 

any appreciated first time have played php , xml.

cheers,

mitchell


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -