Solved

Pulling data from an xml file.

Posted on 2008-10-31
4
593 Views
Last Modified: 2012-06-21
Trying to import an XML file into a database using Binkers example:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_22939751.html

Getting Error:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /home/tylerweb/public_html/replay247.com/xml_test.php on line 24

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: $return in /home/tylerweb/public_html/replay247.com/xml_test.php on line 24

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tylerweb/public_html/replay247.com/xml_test.php on line 24

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/tylerweb/public_html/replay247.com/xml_test.php:24 Stack trace: #0 /home/tylerweb/public_html/replay247.com/xml_test.php(24): SimpleXMLElement->__construct('$return') #1 {main} thrown in /home/tylerweb/public_html/replay247.com/xml_test.php on line 24

Line 24: $xml = new SimpleXMLElement($xmlstr);:


$url = "http://fccwebservice.freeconferencecall.com/fcc.asmx/RegisterByName?Partner=replay247&FullName=Jeffrey%20Morris&Email=jeff@jncmorris.com&TestMode=false";
 
// echo "\n$url";
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
 $return=curl_exec ($ch);
 curl_close ($ch);
 
$xmlstr = '$return';
$xml = new SimpleXMLElement($xmlstr);
//@$xml = new SimpleXMLElement($xmlstr); 
 
 
$sql = ("INSERT INTO tblconfline (MemberID, FCCID, FCCPhonenumber, FCCAccessCode, FCCPIN, FCCPlaybackNumber, FCCErrorMsg, FCCTestMode, RecDate)
VALUES
('" . $_SESSION['memberid'] . "', 
'" . $xml->FCCID . "', 
'" . $xml->FCCPhonenumber . "', 
'" . $xml->FCCAccessCode . "', 
'" . $xml->FCCPIN . "', 
'" . $xml->FCCPlaybackNumber . "', 
'" . $xml->FCCErrorMsg . "', 
'" . $xml->FCCTestMode . "',  
NOW())") or die ("Error adding the record"); 
$result = mysql_query($sql) or die ('Database error: '. mysql_error());
if ($result) { echo "updated <br>"; }

Open in new window

0
Comment
Question by:Jeff
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22853355
instead of:
$xml = new SimpleXMLElement($xmlstr);

try:
$xml = new SimpleXMLElement( file_get_contents($url) );
0
 

Author Comment

by:Jeff
ID: 22853901
That's why you're the Guru!
Thanks again!

Quick question:
$xml = new SimpleXMLElement( file_get_contents($url) );
@$xml = new SimpleXMLElement( file_get_contents($url) );

What does the @ do?
0
 
LVL 82

Expert Comment

by:hielo
ID: 22854076
>>What does the @ do?
supresses any potential warning/error messages. Without it, the warning/error will be sent to the browser.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22854232
glad to help
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with SimpleXML charts with PHP 4 94
Viewing XML as a table on a Mac 3 129
Path of Workbook 3 77
Create XML 5 49
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question