Сохранить XML-файл без декларации — с конкретным адресом

Я пытаюсь найти способ сохранить файл XML после его редактирования, не включая объявление. Но мне нужно иметь возможность установить адрес. Поскольку я сохраняю исходный XML и сохраняю его во временном местоположении (копия оригинала для доступа к javascript, так как оригинал находится в локальном файле).

Поэтому я попробовал $ dom-> saveXML ($ xml-> documentElement); но выходит с некоторыми ошибками сохранения.
Это php-страница, которая получает данные формы и сохраняет их в загруженном в настоящий момент формате xml, а затем сохраняет их и другую копию (внизу кода ниже)

<?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 it and a 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 to set ID on Layer tag - gets value from the Objects->OverlayId attribute
$getId = $rootTag->getAttribute('OverlayId');
//used to set ID on Object tag
$numObj = $xml->getElementsByTagName('Object')->length;

//commstag determines colours for Pen and Brush tags
$commsTag = $xml->createElement("comms",$_REQUEST["comms"]);//convert from deg to 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 and 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 and Coordinate to Coordinates
$coordsTag->appendChild($refcoordTag);
$coordsTag->appendChild($coordTag);
//append Pen, Brush, CircleSelector and Font to GraphicPrimitive
$graphicPrimTag->appendChild($penTag);
$graphicPrimTag->appendChild($brushTag);
$graphicPrimTag->appendChild($circleTag);
$graphicPrimTag->appendChild($fontTag);
//Append Layer, GraphicPrimitive, Coordinates to Graphic
$graphicTag->appendChild($layerTag);
$graphicTag->appendChild($graphicPrimTag);
$graphicTag->appendChild($coordsTag);
//Append Graphic to Object
$objectTag->appendChild($graphicTag);
$objectTag->appendChild($accessTag);
//Append Object to Objects
$rootTag->appendChild($objectTag);

echo($fileUrl);
$xml->save($fileUrl);
$xml->save("..temp/".$fileName);
exit();
};

Я попытался запустить их (первый, чтобы сохранить в месте, откуда я предполагаю, что $ xml был загружен, а второй во временную папку для javascript — второй может иметь объявление).

$xml->saveXML($xml->documentElement);
$xml->save("..temp/".$fileName);

Но получите эту ошибку ниже

Warning: DOMDocument::save(..temp/bms_overlays.xml) [domdocument.save]: failed to open stream: No such file or directory in D:\Programs\server2go\htdocs\analyst\scripts\createcontent.php on line 152

Любая помощь будет принята с благодарностью, так как я впервые играю с php и xml.

Ура,

Mitchell

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector