hi every one
could any one help with the following problem:
the following code building 2 dom trees the first is to get attribute and two children for a particuler node from input.xml file ,and the secound is to create and write to anther file the nodeset of the first dom
the secound dom will be written to file with the session_id name .xml that mean every user will have different file name which means the following code will write to unwell formed xml file
if i added the process instruction header at the begining , this will resulted to unwell formed document as well
i need to find a way that (may be dom ) that allows writting to well formed xml document
thanks for your help
<?php
session_start();
$new= $_GET['new'];
$dom1 = new DOMDocument;
$dom1->Load('input.xml');
$xpath = new DOMXPath($dom1);
$query = "//answer[@id = '$new']";
$entries = $xpath->query($query);
foreach ($entries as $entry) {
$attrt=$entry->getAttribute('id');
$answer_text=$entry->childNodes->item(0)->nodeValue;
$desc_result=$entry->childNodes->item(1)->nodeValue;
}
$dom2 = new DomDocument;
$parent_node = $dom2->createElement('result');
$attr = $parent_node->setAttributeNode(new DOMAttr('rest_id',$attrt));
$parent_node->appendChild($dom2->createElement('answer_text',$answer_text));
$parent_node->appendChild($dom2->createElement('desc-result',$desc_result));
$dom2->appendChild($parent_node);
$contents= $dom2->saveXML($parent_node);
$session_id_file=session_id();
$file_handle = fopen($session_id_file.'.xml','a+');
fseek($file_handle,-10,SEEK_END);
fwrite($file_handle,$contents.'</results>');
fclose($file_handle);
?>