saving xml file from php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barry_normal
Forum Newbie
Posts: 21
Joined: Sun Jul 02, 2006 5:02 am

saving xml file from php

Post 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
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Wouldn't you use DomDocument->dump_file to save the XML document?

Where did you get the DomDocument->save_xml? :?
barry_normal
Forum Newbie
Posts: 21
Joined: Sun Jul 02, 2006 5:02 am

Post 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
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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
Post Reply