Hi,
I am having issues using simplexml. I have generated an XML file using PHP ( link), and I am trying to load it into a simplexml object using: - $xml = simplexml_load_file("news_headlines_xml.php");
This is generating a parser error:
Warning: simplexml_load_file() [function.simplexml-load-file]: news_headlines_xml.php:72: parser error : Start tag expected, '<' not found in /home/airfront/public_html/FedEx4/functions.php on line 5
Warning: simplexml_load_file() [function.simplexml-load-file]: $xmlString = '<?xml version="1.0" encoding="utf-8"?>'; in /home/airfront/public_html/FedEx4/functions.php on line 5
It looks as if it's trying to parse the actual PHP script, and not the generated XML. I have set the MIME type on the PHP file to text/xml. Here is the script that generates the XML: -
// Begin XML
-
$xmlString = '<?xml version="1.0" encoding="utf-8"?>';
-
$xmlString .= "<NEWS>";
-
-
// Begin data output
-
if($getPostCount<count($posts)){
-
for($b=0;$b<$getPostCount;$b++){
-
$xmlString .= "<ARTICLE>";
-
$xmlString .= "<AUTHOR>" . $postArray[$posts[$b]]['poster_name'] . "</AUTHOR>";
-
$xmlString .= "<SUBJECT>" . str_replace("\"", """, $postArray[$posts[$b]]['post_subject']) . "</SUBJECT>";
-
$xmlString .= "<TIME>" . $postArray[$posts[$b]]['post_time'] . "</TIME>";
-
$xmlString .= "</ARTICLE>";
-
}
-
}
-
$xmlString .= "</NEWS>";
-
-
echo $xmlString;
-
I am pretty new to XML, is this even possible? If not, what other methods are available to me?
7 10876 Atli 5,058
Expert 4TB
Hi.
That should work fine, yea.
However, the link you gave us isn't outputting anything.
Therefore your simplexml_load_file call fails, having nothing to parse.
Are you sure the script that generates the XML is working correctly?
Did you perhaps forget to upload it, or uploaded a old version of it?
Doh, I apologize, I was using a work-around, which broke that file...it's back to the way it was, and it looks like a valid XML file =(
Atli 5,058
Expert 4TB
Ok. Did that fix the simplexml issue to?
I tried this a simple test on my own server, and it worked fine. - <?php
-
header("content-type: text/plain");
-
-
$ex = simplexml_load_file("http://www.airfrontierva.com/FedEx4/news_headlines_xml.php");
-
-
foreach($ex->ARTICLE as $_article) {
-
echo "Article: \n";
-
echo " - Author:\t", $_article->AUTHOR, "\n";
-
echo " - Subject:\t", $_article->SUBJECT, "\n";
-
echo " - Time:\t", $_article->TIME, "\n";
-
}
-
?>
And I got these results: - Article:
-
- Author: Anonymous
-
- Subject: Filing Flight Reports
-
- Time: 1213043343
-
Article:
-
- Author: FDX250 Fred
-
- Subject: Website Address in Remarks Section of Flightplan
-
- Time: 1220920102
-
Article:
-
- Author: FDX1032 Jesse
-
- Subject: Pilot Operating Handbook Update
-
- Time: 1222778802
-
Article:
-
- Author: FDX631 - Renato
-
- Subject: NOTAM - South America - SID CHANGE of HUB Campinas
-
- Time: 1224599515
-
Article:
-
- Author: FDX631 - Renato
-
- Subject: HUB Campinas (SBKP) VOR PSN/PIR
-
- Time: 1227142677
Interesting....I copied your script to test.php, it errors out the same. I did have to change the path to the file because my server does not allow URL access. Perhaps this is a server issue, or if it's not give in URL format it interprets the file differently? ( link)
Warning: simplexml_load_file() [function.simplexml-load-file]: news_headlines_xml.php:73: parser error : Start tag expected, '<' not found in /home/airfront/public_html/FedEx4/test.php on line 4
Warning: simplexml_load_file() [function.simplexml-load-file]: $xmlString = '<?xml version="1.0" encoding="utf-8"?>'; in /home/airfront/public_html/FedEx4/test.php on line 4
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/airfront/public_html/FedEx4/test.php on line 4
Warning: Invalid argument supplied for foreach() in /home/airfront/public_html/FedEx4/test.php on line 6
Atli 5,058
Expert 4TB
If you give it a file path, it will read the file as it is... meaning it will read the PHP code.
If you give it a URL, it will request the file via a HTTP server, which will execute the PHP code and return the output.
I see, i'll petition my provider to enable URL access....thanks so much for your help!
Atli 5,058
Expert 4TB
No problem.
But there is an easier solution.
You can include your PHP file into your script and get the value like that.
For example: -
<?php
-
/**
-
* File: createXML.php
-
*/
-
$xmlString = "";
-
// Insert code to create some XML here
-
-
return $xmlString
-
?>
-
<?php
-
/**
-
* File: index.php
-
*/
-
$xmlString = include("createXML.php");
-
-
$parsed = simplexml_load_string($xmlString);
-
-
// etc...
-
?>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rainer Mohr |
last post by:
Hi,
I´m having some problems with simplexml_load_file() and cant find any
sollution anywhere.
Say, we have the following file:
---file.xml---
<UNITS>Metric</UNITS>
<UNITS>another</UNITS>...
|
by: malcolm |
last post by:
Hello,
We have a robust (.NET 1.1 c# winforms) client-server application that
utilizes many typed DataSets, typed DataTables and typed DataRows. Our
application is a series of windows and popup...
|
by: eschneider |
last post by:
Just some common issues with WS:
Using custom objects: When objects change, seems you are always fixing some
issue. Update references, which sometimes does not work.
Deployment:
Weird errors...
|
by: Harsha |
last post by:
Hi All,
I am using simplexml_load_file function to parse xml files on
my localhost. But the server hosting my domain has php 4.x.x. so i
want to use php 4.x.x instead,
Is there a way to install...
|
by: alexus |
last post by:
i have test.xml file that i pull from someone, and when i try to load
it up into php
I get this
mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$
|
by: SnakesRule |
last post by:
I'm trying to pull data from remote xml files to load the database of a library. My sources are www.amazon.com and www.ISBNdb.com. But when I try to search and read the xml files, I get this error:
...
|
by: newzdog |
last post by:
Hi,
I have a problem parsing an rss feed using simplexml_load_file - this is strange as i have used the same code to parse literally 1000s of different rss feeds in the past, and even stranger in...
|
by: cudan706 |
last post by:
When i use Simplexml_load_file. How can i close or end load file process xml when simplexml_load_file.
example:
<?php
$xml = simplexml_load_file("path_to_xml");
foreach()
{
//example code
}...
|
by: ziycon |
last post by:
How can I search the object from simplexml_load_file() to pull out certain nodes? Haven't had any luck searching for help on it?
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |