Printing XML String

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
michel77
Forum Newbie
Posts: 17
Joined: Sun Nov 06, 2005 4:57 am

Printing XML String

Post by michel77 »

How to print an XML String ? Simply print the String doesn't work. Loading with simplexml_load_string and using print_r shows only the structure, not the data. I would like to print the whole String exactly. How to do it ?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: Printing XML String

Post by foobar »

You mean, just print out the textual contents?

Code: Select all

$fp = fopen('/path/to/file.xml', 'r');

while ($tmp = fread($fp, 4096)) {
  $file .= $tmp;
}

echo $file;
^Works for any file.
michel77
Forum Newbie
Posts: 17
Joined: Sun Nov 06, 2005 4:57 am

Post by michel77 »

Here an axample:

$xml = '<?xml version="1.0" encoding="UTF-8"?>';
print ($xml);

this doesn't work
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

michel77 wrote:Here an axample:

$xml = '<?xml version="1.0" encoding="UTF-8"?>';
print ($xml);

this doesn't work
Yes it does. You just won't see it in your browser. Check the output's source code.
michel77
Forum Newbie
Posts: 17
Joined: Sun Nov 06, 2005 4:57 am

Post by michel77 »

You are right. But not only the browser also Eclipse (PHP Browser) doesn't show it. Do you know how the access the output within eclipse or how to redirect into a file ?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

michel77 wrote:You are right. But not only the browser also Eclipse (PHP Browser) doesn't show it. Do you know how the access the output within eclipse or how to redirect into a file ?
Not sure what you want to do, but I assume you want to save the xml output as a file?
michel77
Forum Newbie
Posts: 17
Joined: Sun Nov 06, 2005 4:57 am

Post by michel77 »

First I would like to get teh output's source code within Eclipse. I know only the PHP browser, that shows the same like Internet Explorer. Addutionally I would like to redirect outpout (print) into a file.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

michel77 wrote:First I would like to get teh output's source code within Eclipse. I know only the PHP browser, that shows the same like Internet Explorer. Addutionally I would like to redirect outpout (print) into a file.
Hm...ok.

Code: Select all

$fp = fopen('/path/to/file.xml', 'r');

while ($tmp = fread($fp, 4096)) {
  $file .= $tmp;
}

fclose($fp2);

/* Write to file */
$fp2 = fopen('/some/other/file.xml', 'w');
fwrite($file, $file);
fclose($fp2);

/* Replaces < and > with < and > */
$file = str_replace('<', '<', $file);
$file = str_replace('>', '>', $file);

/* Output the contents */
echo $file;
Post Reply