teşekkürler xml + php öğrenmek için bana yardımcı olmak için tüm!
I want to make an Autoincrement for the id child node. in my createxml.php i'm the one who enter the id.. i want to be able to know what is the maxium value of all id's and then the id=max_value++
Ben de kendime açıklamak umuyoruz.
this is the events.xml file:
<events>
<record>
<id>1</id>
<event>a</event>
<eventDate>a</eventDate>
<desc>a</desc>
</record>
<record>
<id>2</id>
<event>b</event>
<eventDate>b</eventDate>
<desc>b</desc>
</record>
</events>
and this is how i adding new child nodes to the xml..
parser.php:
<?php
header("Content-type: text/html; charset=utf-8");
$record = array(
'id' => $_POST['id'],
'event' => $_POST['event'],
'eventDate' => $_POST['eventDate'],
'desc' => $_POST['desc'],
);
$doc = new DOMDocument();
$doc->load( 'events.xml' );
$doc->formatOutput = true;
$r = $doc->getElementsByTagName("events")->item(0);
$b = $doc->createElement("record");
$id = $doc->createElement("id");
$id->appendChild(
$doc->createTextNode( $record["id"] )
);
$b->appendChild( $id );
$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("events.xml");
header("Location: {$_SERVER['HTTP_REFERER']}");
?>
Thanks all for helping!