473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SimpleXML and load php file (Content-type: text/xml)

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.

Jan 14 '07 #1
2 12354
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.
Jan 15 '07 #2

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.

Jan 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Wolfgang May | last post by:
Hi, I have a problem with the HTTP implementation of the PEAR package: I try to PUT an XML instance to an XML database (eXist), but it always puts a binary: <?php require_once...
2
by: Gustaf Liljegren | last post by:
I need to merge several XML files into one large. All of them has a DOCTYPE tag, but the SYSTEM identifier points to a DTD that doesn't exist. (I use the PUBLIC identifier with catalog files, so...
1
by: Andy Britcliffe | last post by:
Hi I'm faced with the situation where I could have a single physical file that could contain multiplie XML documents e.g file.txt contains the following: <?xml version="1.0"...
0
by: Sriram | last post by:
I have created a web service using C#. This basically receives a string as a parameter and returns an XML string. There is a specific requirment that the users should be able to call this web...
0
by: delphiconsultingguy | last post by:
This code assumes that you have a LoggingMessagesDefinition.XSD file, a LoggingMessagesDefinition.XML file that conforms to the XSD, and that you have used the XSD.exe utility to create a c# .cs...
4
by: Sergei Shelukhin | last post by:
Hi. The question may be stupid, but when I try ti produce asp file that outputs xml the way I did it in 1.1 - by emptying the aspx file itself or adding something like <?xml version="1.0"...
3
by: yingwen | last post by:
How can I read a XML file into a xml string. I have tried streamreader, xmltextreader, the out put results only give me the text() part of xml file(all xml tags are not included in the output). ...
12
by: TS | last post by:
i have a need to possibly enable mutli language support. What benefit do i get by using a resource file instead of a custom xml solution? thanks!
3
by: K Viltersten | last post by:
I've been informed that a webserver sending a XML file is supposed to add "Content-Type: text/xml header". I'm not questioning that infromation but i'm unsure what was ment by it. The XML i get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.