PDA

View Full Version : PHP & XML question


Dr_s99
02-05-05, 08:59 PM
Hello,
i have a XML file that looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<maindatabase>
<car id="1">
<picture id="1">car1.jpg</picture>
<stock_num>378</stock_num>
<year>2000</year>
<make>CHEVROLET</make>
<model>MALIBU</model>
<model_det>V6 LS</model_det>
<date>2/5/2005</date>
<mileage>84000 km</mileage>
<price>$8,995.00</price>
<pic_gallery>00</pic_gallery>
</car>
</maindatabase>


i want to make a "control center" for it....
i mean i want to make a page where you enter all the information and the program saves it into the XML file....

basic idea is i have
around 10 textfields for each nodes...
and when the user clicks submits, the page opens that XML file and appends the information the user has inputed into it.
in the same formate...

<car>
....
</car>

is there any tutorial out there that shows something similar.??

or any idea...

PS: i'm just learning PHP...lol ,
i got the viewing part working... though...lol


Thank you,
dr_s99

de><ta
02-06-05, 06:15 PM
Trying checking out www.tutorialized.com to see if it has anything that you may find usefull.

I have yet to learn XML properly however I do know PHP (which I learnt mainly from the site mentioned above :eek: ).

Dr_s99
02-07-05, 05:41 PM
Thank you,
except i have a question..lol


$doc = new_xmldoc("1.0");
// Adding root node
$root = $doc->add_root("maindatabase");
// Setting attribute for the root node
//$root->set_attribute("Title","XML and PHP");
$root_sec= $root->new_child("Cars");
$root_sec->set_attribute("id","1");
// Adding children to the root node
$picture = $root_sec->new_child("picture","ss");
$stock_num = $root_sec->new_child("stock_num","145");
$years = $root_sec->new_child("year", ";;");
$make = $root_sec->new_child("make", "-");
$model = $root_sec->new_child("model", "---");
$model_det = $root_sec->new_child("model_det", "-|-");
$date = $root_sec->new_child("date", "||-");
$mileage = $root_sec->new_child("mileage", "|||");
$price = $root_sec->new_child("price", "||/");
$pic_gallery = $root_sec->new_child("pic_gallery", "|\/");
echo $doc->dumpmem();
print "$new_xmldoc";
$fp = fopen("test.xml", "w+");



i have this code.. how could i tell it to append and not to overwrite the fie?

de><ta
02-07-05, 08:51 PM
To apend text to the end of test.xml (basically the pointer is set to the location where the EOF of test.xml occurs),

$fp = fopen("test.xml", "a");

The rest of the specifications can be found here:
http://us3.php.net/fopen