I'm trying to write on xml file. but my server have DOM as disabled. so i can't use the DOM function.
is there a way to write on xml other then DOM?
Files:
xml:
<?xml version="1.0" encoding="UTF-8"?>
<events>
<record>
<event>aaa</event>
<eventDate>bbb</eventDate>
<desc>ccc</desc>
</record>
parser.php:
header("Content-type: text/html; charset=utf-8");
$record = array(
'event' => $_POST['event'],
'eventDate' => $_POST['eventDate'],
'desc' => $_POST['desc'],
);
$doc = new DOMDocument();
$doc->load( 'calendar.xml' );
$doc->formatOutput = true;
$r = $doc->getElementsByTagName("events")->item(0);
$b = $doc->createElement("record");
$event = $doc->createElement("event");
$event->appendChild(
$doc->createTextNode( $record["event"] )
);
$b->appendChild( $event );
$eventDate = $doc->createElement("eventDate");
$eventDate->appendChild(
$doc->createTextNode( $record["eventDate"] )
);
$b->appendChild( $eventDate );
$desc = $doc->createElement("desc");
$desc->appendChild(
$doc->createTextNode( $record["desc"] )
);
$b->appendChild( $desc );
$r->insertBefore( $b,$r->firstChild );
$doc->save("calendar.xml");
header("Location: {$_SERVER['HTTP_REFERER']}");
what can i do?
if you're using PHP5 you can use SimpleXML
You could edit the file as if it were a plain text file. However, you will need to make sure all elements are closed and all data is escaped correctly. If you only need to output XML this is doable, but to write a parser that can add to and modify existing XML data is a tough job. Better try to enable DOM or find an out of the box library.