Page 1 of 1

saving xml file from php

Posted: Thu Jul 13, 2006 4:37 pm
by barry_normal
Hello there, I'm sure this should be easy but I just can't work it out. Please help.

I've created a domxml doc like this:

Code: Select all

$docOut = domxml_new_doc("1.0");
$root = $docOut->create_element("locations");
$root = $docOut->append_child($root);
$detail = $docOut->create_element("location");
$detail = $root->append_child($detail);
$text = $docOut->create_text_node($LocationInfo);
$text = $detail->append_child($text);
print $docOut->save_xml("test.xml");
Problem I'm having is that this doesn't save a document. It gives a fatal error. So does all the other combinations I've tried.

If anyone knows the right way to do this. Please put me out of my misery.

Cheers!
B

Posted: Thu Jul 13, 2006 4:51 pm
by Buddha443556
Wouldn't you use DomDocument->dump_file to save the XML document?

Where did you get the DomDocument->save_xml? :?

Posted: Thu Jul 13, 2006 5:17 pm
by barry_normal
Thanks so much Buddha443556,

I got save_xml from having tried createElement() first (as it says in the text book I was reading) and then discovering that subsequently it was actually create_element(). Just thought I'd give it a try.

But I've used dump now and it works like a dream.

All the best
B

Posted: Thu Jul 13, 2006 6:51 pm
by Buddha443556
barry_normal wrote:I got save_xml from having tried createElement() first (as it says in the text book I was reading) and then discovering that subsequently it was actually create_element().
Ahh ... been there. These days some textbooks can be out of date before the ink dries.

Best regards,
Buddha