
February 8th, 2004, 08:15 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Problem: Adding a child in a XML file with PHP & DOM
I have this xml file:
Code:
<?xml version='1.0' encoding='ISO-8859-1'?>
<news>
<new type="Trips">
<title>I'm going to Amsterdam</title>
<date>07/02/04</date>
<content>Yesterday, I decide to go to Amsterdam with my friend of NEWI, we decide to go 7 days and now we are nervous</content>
</new>
<new type="Me">
<title>I'm very happy</title>
<date>05/02/04</date>
<content>Today I've spoken with my best friend and now i'm very happy</content>
</new>
</news>
Now, I want to add a new new child of news with the sames childs but with different information.
The information is not a problem but I don't know why but I can't find a good solution for my problem.
I've start to do some like that but this simple code doesn't work:
Some ideas??
PHP Code:
<html>
<head>
<title>Sugerencias</title> </head>
<?php
$ttl = $_POST["title"];
$cnt = $_POST["content"];
$Sub = $_POST["subject"];
$dom = domxml_open_file("news.xml") OR die ("Couldn't load news.xml"); $elements = $dom->get_elements_by_tagname("new");
$element = $elements[0];
$newnode = $element->insert_before($element, $element);
echo "<PRE>"; $xmlfile = $dom->dump_mem();
echo htmlentities($xmlfile);
echo "</PRE>";
</body>
</html>
Thanks a lot!!!
|