/    Sign up×
Community /Pin to ProfileBookmark

PHP DOM and saveXML() Method !!

Hi,

I’m creating a new XML Document in php using PHP DOM and when i use the method saveXML() i just get a blank string instead of a string with the content of the xmlDoc that i created. Here is the code :

[CODE]<?php
$doc = new DOMDocument(‘1.0’);
$doc->formatOutput = true;

$root = $doc->createElement(‘book’);
$root = $doc->appendChild($root);

$title = $doc->createElement(‘title’);
$title = $root->appendChild($title);

$text = $doc->createTextNode(‘This is the title’);
$text = $title->appendChild($text);

echo “Retrieving all the document:n”;
echo $doc->saveXML() . “n”;

echo “Retrieving only the title part:n”;
echo $doc->saveXML($title);
?>[/CODE]

Does anyone knows what is the problm ??

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMar 15.2006 — on both lines or just one?

what version are you using?
Copy linkTweet thisAlerts:
@ivobeneditoauthorMar 15.2006 — Yes ... in both method's with and without arguments it isn't working !!

I'm using php 5.1.2, but i installed it as a cgi binary in IIS !! Is it possible to be that the problm ??


EDIT : I already tried in a PC with apache/PHP 5.1.2 as Apache DLL Module and that didn't worked 2. What am i doing wrong ? ???
Copy linkTweet thisAlerts:
@bokehMar 15.2006 — <>
Copy linkTweet thisAlerts:
@bokehMar 15.2006 — I have looked at this a few times now and what the problem is, is that you are just outputing your code to the browser under the default [I]text/html[/I] media type. That means the browser formats it as html and uses the text between <title> elements in the title bar of the document. If you are just outputing your XML for test purposes do this: [code=php]echo '<pre>' . htmlentities($doc->saveXML()) . '</pre>';[/code]
Copy linkTweet thisAlerts:
@ivobeneditoauthorMar 16.2006 — Tks for the help bokeh ? !! I just don't understand how that isn't mentioned in all the many tut's and php manual where i took the code from.

BTW, we can also change the content type header to get the ouput page as a xml page and then it will work 2.

[CODE]header('Content-type: text/xml'); [/CODE]


[]]'s
Copy linkTweet thisAlerts:
@bokehMar 16.2006 — BTW, we can also change the content type header to get the ouput page as a xml page and then it will work 2.

[CODE]header('Content-type: text/xml'); [/CODE] [/QUOTE]
That's true but i suggested my method because If you are just testing it is quite possible you are outputing other things as well and just throwing in a header might have broken the output.
×

Success!

Help @ivobenedito spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...