petersprc ha scritto:
Hi,
To parse that XML, you would want to do something like:
<?php
$xml = "<?xml version='1.0' standalone='yes'?>" .
"<movies><movie>A</movie><movie>B</movie></movies>";
$el = new SimpleXMLElement($xml);
echo $el->movie[0];
?>
You wouldn't want to call simplexml_load_file directly on a PHP source
file, only valid XML output...
whisher wrote:
Hi.
I'm taking my first steps with xml and SimpleXML functions.
xml.php
(It could be made dynamically with a mysql result
I post this snippet for example )
PHP Code xml.php:
<?php
$xmlstr = "<?xml version=\"1.0\" standalone=\"yes\"?>";
$xmlstr .= "<movies>\n<movie>Behind the Parser</movie>\n</movies>\n";
header('Content-type: text/xml; charset=utf-8');
echo $xmlstr;
?>
PHP Code loadXml.php:
I've got this nasty error :
Warning: xml.php:2: parser error : Start tag expected, '<' not found in
c:\xxx\www\xml\example\mioplot.php on line 3
Warning: $xmlstr = ""; in c:\xxx\www\xml\example\loadXml.php on line 3
Warning: ^ in c:\xxx\www\xml\example\loadXml.php on line 3
bool(false)
I've got the same error in my web site .
xml.php is a valid xml file, isn't it ?
Therefore I'm wondering why the snippet
doesn't work ?
Thanks in advance.
Bye.
Hi.
Thanks so much for the ready replay.
I'm used to split up all the tasks
in my script therefore I can't follow
your tip.
Well with Ajax, for instance I can
manage a file like that without any
hassle.
I'm wondering how on earth I can't do it
with Php by SimpleXML :( .
I could do a thing like this :
$doc = new DOMDocument('1.0');
// we want a nice output
$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);
$doc->save("newfile.xml");
But doing it I would develop a caching
system with more work :((((
Thanks again.
Take care.