473,806 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issues with simplexml_load_ file

33 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. $xml = simplexml_load_file("news_headlines_xml.php");
This is generating a parser error:
Warning: simplexml_load_ file() [function.simple xml-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.simple xml-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:

Expand|Select|Wrap|Line Numbers
  1. // Begin XML
  2. $xmlString =  '<?xml version="1.0" encoding="utf-8"?>';
  3. $xmlString .= "<NEWS>";
  4.  
  5. // Begin data output
  6. if($getPostCount<count($posts)){
  7.     for($b=0;$b<$getPostCount;$b++){
  8.         $xmlString .= "<ARTICLE>";
  9.         $xmlString .= "<AUTHOR>" . $postArray[$posts[$b]]['poster_name'] . "</AUTHOR>";
  10.         $xmlString .= "<SUBJECT>" . str_replace("\"", "&quot;", $postArray[$posts[$b]]['post_subject']) . "</SUBJECT>";
  11.         $xmlString .= "<TIME>" . $postArray[$posts[$b]]['post_time'] . "</TIME>";
  12.         $xmlString .= "</ARTICLE>";
  13.     }
  14. }
  15. $xmlString .= "</NEWS>";
  16.  
  17. echo $xmlString;
  18.  
I am pretty new to XML, is this even possible? If not, what other methods are available to me?
May 31 '09 #1
7 10909
Atli
5,058 Recognized Expert Expert
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?
May 31 '09 #2
flydev
33 New Member
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 =(
May 31 '09 #3
Atli
5,058 Recognized Expert Expert
Ok. Did that fix the simplexml issue to?

I tried this a simple test on my own server, and it worked fine.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("content-type: text/plain");
  3.  
  4. $ex = simplexml_load_file("http://www.airfrontierva.com/FedEx4/news_headlines_xml.php");
  5.  
  6. foreach($ex->ARTICLE as $_article) {
  7.     echo "Article: \n";
  8.     echo " - Author:\t", $_article->AUTHOR, "\n";
  9.     echo " - Subject:\t", $_article->SUBJECT, "\n";
  10.     echo " - Time:\t", $_article->TIME, "\n";
  11. }
  12. ?>
And I got these results:
Expand|Select|Wrap|Line Numbers
  1. Article: 
  2.  - Author:    Anonymous
  3.  - Subject:    Filing Flight Reports
  4.  - Time:    1213043343
  5. Article: 
  6.  - Author:    FDX250 Fred
  7.  - Subject:    Website Address in Remarks Section of Flightplan
  8.  - Time:    1220920102
  9. Article: 
  10.  - Author:    FDX1032 Jesse
  11.  - Subject:    Pilot Operating Handbook Update
  12.  - Time:    1222778802
  13. Article: 
  14.  - Author:    FDX631 - Renato
  15.  - Subject:    NOTAM - South America - SID CHANGE of HUB Campinas
  16.  - Time:    1224599515
  17. Article: 
  18.  - Author:    FDX631 - Renato
  19.  - Subject:    HUB Campinas (SBKP) VOR PSN/PIR
  20.  - Time:    1227142677
May 31 '09 #4
flydev
33 New Member
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.simple xml-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.simple xml-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.simple xml-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
May 31 '09 #5
Atli
5,058 Recognized Expert Expert
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.
May 31 '09 #6
flydev
33 New Member
I see, i'll petition my provider to enable URL access....thank s so much for your help!
May 31 '09 #7
Atli
5,058 Recognized Expert Expert
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /**
  3.  * File: createXML.php
  4.  */
  5.   $xmlString = "";
  6.   // Insert code to create some XML here
  7.  
  8.   return $xmlString
  9. ?>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /**
  3.  * File: index.php
  4.  */
  5. $xmlString = include("createXML.php");
  6.  
  7. $parsed = simplexml_load_string($xmlString);
  8.  
  9. // etc...
  10. ?>
May 31 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3714
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> --------------
2
2325
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 windows where you can edit information and data, nothing out of the ordinary. I estimate we have something like 50 to 100 tables and/or views in our database each of which map to one strongly typed DataTable. Now we have some odd 20 to 30 typed...
3
1661
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 which take a while to fix because the error stink: Forget to set ASP.NET 2.0="Parser Error Message: Could not load type" '*.Global' is ambiguous: it could come from assembly=I deleted the
2
6497
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 simplexml_load_file function on php 4, if yes PLEASE let me know, else PLEASE suggest a function to parse xml files easily...... Thank u....
7
6067
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$
1
7208
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: When I open the resulting URLs in a browser, I can see the xml data just fine, and I have tried this on to different computers and servers, with the same result. Here is my code (minus the access keys for the databases):
4
11361
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 that if i put the feed source on our server as a .xml file then my code parses it successfully. The relevant code snippet: $xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2",'SimpleXMLElement', LIBXML_NOCDATA); The errors i get...
2
5762
cudan706
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 } //this here, please help me close simplexml_load_file() process.
5
3147
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?
0
9718
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.