php - Loading a string into simplexmlelement -


i trying post data web service. evidently wrong on side sent me example code. example allowed me enter data hand , submit service. works , sends text area full of xml data plus user/id. have page setup poll database , extract outstanding orders. trying send txnid paypal new page can compile xml , send it. figured drop same code used failed method. xml formatted correctly wrong when try use simplexmlelement function. took data passed text field , worked fine. error:

php fatal error: uncaught exception 'exception' message 'string not parsed xml'

here code thats giving error

include('connect-db.php');                                    // records database if ($result = $mysqli->query("select * paypal_payment_info txnid = '" .$_get['txnid']. "'")) {     // display records if there records display    if ($result->num_rows > 0)     {         $row = $result->fetch_object();          // set row each record          $weborderxml = "<workorder>                   <orderid>127834</orderid>                   <ordertype>test</ordertype>                   <projectcode> </projectcode>                   <projectshipdate></projectshipdate>                   <retailerpo></retailerpo>                   <lineitems>                     <lineitem>                       <linenumber>1</linenumber>                       <productcode>3pf-dd-slpgz6</productcode>                       <productupc></productupc>                       <itemdescription>filename</itemdescription>                       <quantity>1</quantity>                       <itemsscc></itemsscc>                       <filelist>                 <source>/images/" . $row->itemname. str_replace(' ', "", str_replace('"', "", $row->os0)).  str_replace('"', "", $row->os1) . str_replace('"', "", $row->os2). ".jpg </source>                       </filelist>                     </lineitem>                   </lineitems>                   <customerbillinginfo>                   </customerbillinginfo>                   <customershippinginfo>                     <name>".$row->firstname. " " . $row->lastname."</name>                     <address1>".$row->street."</address1>                     <address2> </address2>                     <city>".$row->city."</city>                     <state>".$row->state. "</state>                     <postalcode>".$row->zipcode."</postalcode>                     <country>".$row->country."</country>                     <shippingmethod>ups</shippingmethod>                     <shipaccountnum></shipaccountnum>                     <shiptype>mth</shiptype>                     <dc> </dc>                   </customershippinginfo>                   <orderproperties>                   </orderproperties>                 </workorder>";                                             }     // if there no records in database, display alert message     else     {             echo "no results display!";     }  } // show error if there issue database query else {         echo "error: " . $mysqli->error; }  // close database connection $mysqli->close();   //$weborderxml = $_post['weborderxml'];//orderxml   $sxml = new simplexmlelement($weborderxml);   $orderidx = $sxml->orderid; 

the text same. can copy , paste resulting string other form , post it. works fine somewhere i'm missing because function not string.

attention if haven't record $weborderxml value null exception shown

fatal error: uncaught exception 'exception' message 'string not parsed xml'

because simplexmlelement() null give in. can check $weborderxml value empty() $weborderxml not null , can put simplexmlelement() inside of try catch control exception

if(!empty($weborderxml)){   try{       $sxml = new simplexmlelement($weborderxml);   }catch(exception $e){       //show error or work   } }  

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -