Page 1 of 1

php with XML

Posted: Thu Dec 21, 2006 1:36 pm
by mavedog21
onion2k | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hope I'm in the right section. Please help, I'm only trying to load an xml into a variable and print it to the screen for now.

I'm having a problem with this code:

Code: Select all

$dom = new DomDocument();
$dom->load("myXMLtest.xml");
I get this output for these lines:

Warning: domdocument() expects at least 1 parameter, 0 given in /home/wildiris/public_html/phpTest/saveToXML.php on line 7

Fatal error: Call to undefined function: load() in /home/wildiris/public_html/phpTest/saveToXML.php on line 8





Here is the whole code:

Code: Select all

echo "<p> Welcome <br/><b>".$_POST["user"]."</b>.";
echo "<p> Email is:<br/><b>".$_POST["email"]."</b>.";
echo "<p> Message is:<br/><b>".$_POST["message"]."</b>.";


$dom = new DomDocument();
$dom->load("myXMLtest.xml");

foreach($dom->documentElement->childNodes as $test){
echo $test;
}

Thanks in advance, I'm stumped.

mavedog21


onion2k | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: php with XML

Posted: Thu Dec 21, 2006 2:22 pm
by Kieran Huggins
mavedog21 wrote:Warning: domdocument() expects at least 1 parameter
http://www.php.net/manual/en/function.d ... struct.php
PHP Manual wrote:$dom = new DOMDocument('1.0', 'iso-8859-1');
Cheers,
Kieran

Posted: Thu Dec 21, 2006 2:24 pm
by volka
You're using php 4 dom domxml? Then take a look at http://de2.php.net/domxml_open_file
http://www.php.net/manual/en/function.dom-domdocument-construct.php wrote:__construct ( [string version [, string encoding]] )
The parameters are in brackets, meaning they are optional

btw: Where's the database question? I think "PHP - Code" is more appropriate.

Posted: Thu Dec 21, 2006 2:39 pm
by Kieran Huggins
whew - I completely missed that - good catch volka!

mavedog21: You're mixing up a DOM XML object (php4) with DOM methods (php5)

if you have php4, refer to this section only:
http://www.php.net/manual/en/ref.domxml.php

If you have php5, refer to this section only:
http://www.php.net/manual/en/ref.dom.php

If you are using php5 (It doesn't look like you are), you may also want to look at:
http://www.php.net/manual/en/ref.simplexml.php

Cheers,
Kieran