Solved

Pulling data from an xml file.

Posted on 2008-10-31
4
590 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:jeffey48
  • 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:jeffey48
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Custom Ribbon doesn't refresh 7 61
Path of Workbook 3 45
XSL - change date format 3 29
XML & .net 5 21
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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, …
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now