'String could not be parsed as XML' when using Search

625 views
Skip to first unread message

Alex Casamassima

unread,
Mar 9, 2016, 3:33:30 PM3/9/16
to PHRETS
I'm having a problem with a basic listing Search with PHRETS...

After logging in successfully to TREB, I attempt a simple Search as such:
$resource = "Property"; 
$class = "ResidentialProperty"; 
$query = "(Status=A)";  
$results = $rets->Search($resource, $class, $query);

TREB does respond with Data, but it appears it cannot be parsed within PHRETS (more particularly through Guzzle/Response) as I get the following error:
Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home.../vendor/guzzlehttp/guzzle/src/Message/Response.php:168
Stack trace:
#0 /home.../vendor/guzzlehttp/guzzle/src/Message/Response.php(168): SimpleXMLElement->__construct('<RETS ReplyCode...', 2048, false, '', false)
#1 /home.../vendor/troydavisson/phrets/src/Parsers/Search/OneX.php(14): GuzzleHttp\Message\Response->xml()
#2 /home.../vendor/troydavisson/phrets/src/Session.php(309): PHRETS\Parsers\Search\OneX->parse(Object(PHRETS\Session), Object(GuzzleHttp\Message\Response), Array)
#3 /home.../hellorets.php(72): PHRETS\Session->Search('Property', 'ResidentialProp...', '(Status=A)')
#4 {main}

Next exception 'GuzzleHttp\Exception\XmlParseException' with message 'Unable to parse response body into XML: String could not be parsed as XML' in /home.../vendor/guzzlehttp/guzzle/ in /home.../vendor/guzzlehttp/guzzle/src/Message/Response.php on line 174

There appears to be a response, as when I wrap the PHRETS\Parsers\Search\OneX->parse function in a try catch, and echo $response->getBody() I get listing data:
<RETS ReplyCode="0" ReplyText="">
<COUNT Records="6910"/>
<DELIMITER value="09"/>
<COLUMNS> A_c Acres Ad_text Addr Apt_num Bath_tot Br Br_plus Bsmt1_out Bsmt2_out Cable Cac_inc Comel_inc Comp_pts County Cross_st Den_fr Depth Drive Elec Elevator Extras Farm_agri Fpl_num Front_ft Fuel Gar_type Gas Heat_inc Heating Hydro_inc Irreg Legal_desc Level1 Level2 Level3 Level4 Level5 Level6 Level7 Level8 Level9 Lotsz_code Lp_dol Ml_num Num_kit Outof_area Parcel_id Park_chgs Park_spcs Pool Prkg_inc Rltr Rm1_len Rm1_out Rm1_wth Rm2_len Rm2_out Rm2_wth Rm3_len Rm3_out Rm3_wth Rm4_len Rm4_out Rm4_wth Rm5_len Rm5_out Rm5_wth Rm6_len Rm6_out Rm6_wth Rm7_len Rm7_out Rm7_wth Rm8_len Rm8_out Rm8_wth Rm9_len Rm9_out Rm9_wth Rms Rooms_plus S_r Sewer Sqft St St_dir St_num St_sfx Status Style Taxes Tour_url Tv Uffi Util_cable Util_tel Vend_pis Water Water_inc Wcloset_p1 Wcloset_p2 Wcloset_p3 Wcloset_p4 Wcloset_t1 Wcloset_t2 Wcloset_t3 Wcloset_t4 Wtr_suptyp Yr Yr_built Zip Zoning Type_own_srch Type_own1_out Constr1_out Constr2_out Prop_feat1_out Prop_feat2_out Oth_struc1_out Oth_struc2_out Rm1_dc1_out Rm1_dc2_out Rm1_dc3_out Rm2_dc1_out Rm2_dc2_out Rm2_dc3_out Rm3_dc1_out Rm3_dc2_out Rm3_dc3_out Rm4_dc1_out Rm4_dc2_out Rm4_dc3_out Rm5_dc1_out Rm5_dc2_out Rm5_dc3_out Rm6_dc1_out Rm6_dc2_out Rm6_dc3_out Rm7_dc1_out Rm7_dc2_out Rm7_dc3_out Rm8_dc1_out Rm8_dc2_out Rm8_dc3_out Rm9_dc1_out Rm9_dc2_out Rm9_dc3_out Ass_year Gar_spaces Lse_terms Vtour_updt Disp_addr Mmap_page Mmap_col Mmap_row All_inc Furnished Laundry Pvt_ent Addl_mo_fee Central_vac Kit_plus Laundry_lev Prop_feat3_out Prop_feat4_out Prop_feat5_out Prop_feat6_out Retirement Rm10_dc1_out Rm10_dc2_out Rm10_dc3_out Rm10_len Rm10_out Rm10_wth Rm11_dc1_out Rm11_dc2_out Rm11_dc3_out Rm11_len Rm11_out Rm11_wth Rm12_dc1_out Rm12_dc2_out Rm12_dc3_out Rm12_len Rm12_out Rm12_wth Waterfront Wcloset_p5 Wcloset_t1lvl Wcloset_t2lvl Wcloset_t3lvl Wcloset_t4lvl Wcloset_t5 Wcloset_t5lvl Spec_des1_out Spec_des2_out Spec_des3_out Spec_des4_out Spec_des5_out Spec_des6_out Level10 Level11 Level12 Timestamp_sql Area_code Municipality_code Community_code Municipality_district Area Municipality Community Idx_dt Pix_updt </COLUMNS>
<DATA> Central Air ** Live In The Nature In The Centre Of Richmond Hill ** Very Private And Mature Neighbourhood ** Top Ranking School Walking Distance To Yonge St, School And Bus Stop, Park And Observatory ** Cathedral Ceiling In Living Room * 3 3 Full E Ontario Y 135.00 Private *** All Elf&apos;s,Fridge And Gas Stove,Central Air Conditioning,Washer And Dryer,Dishwasher,Central Vauum,Gas Fireplace,Broadloom Where Laid *** Y 50.00 Gas Attached Forced Air Main Main Main Main Main Main Main Main Main Feet 1049000.00 N3425984 1 4 None RE/MAX WEST REALTY INC., BROKERAGE 8.36 Living 3.35 8.36 Dining 3.35 3.84 Kitchen 2.44 3.48 Breakfast 3.10 4.56 Family 3.35 4.88 Master 3.35 3.71 2nd Br 2.74 3.71 3rd Br 3.05 1.91 Laundry 1.73 7 Sale Sewers A Bungalow 4650.95 N Municipal 4 3 2 1 2015 D. Detached Brick Cathedral Ceiling Combined W/Dining Combined W/Living Hollywood Kitchen Ceramic Floor Sliding Doors Ceramic Floor W/O To Deck Gas Fireplace O/Looks Garden 4 Pc Ensuite His/Hers Closets Broadloom Broadloom Ceramic Floor 2.0 N Unknown 2016-03-09 12:05:03.0 09 09.04 09.04.0100 Richmond Hill York Richmond Hill Harding 2013-01-16 09:42:51.0 2016-03-02 10:32:43.0 </DATA>
<DATA> ... Alot more data ...

The Response does look like proper XML, however... I'm not certain if that is the proper response for a 1.7 implementation of RETS, or if there are other settings I may have missed. As far as I'm concerned I made a proper Query, and got a proper response, but right now I have no success at obtaining the results from said query.

Someone please advise :) 
Thanks!

Alex Casamassima

unread,
Mar 9, 2016, 3:58:41 PM3/9/16
to PHRETS
Interestingly enough, I do not get the parsing error if I limit the quantity of results in search... Not sure to why this is the case however, the following did work:

$resource = "Property"; 
$class = "ResidentialProperty"; 
$query = "(Status=A)"; 
$results = $rets->Search($resource, $class, $query, ['Limit' => 10]);


Gennadiy Kofman

unread,
Mar 9, 2016, 6:00:43 PM3/9/16
to PHRETS
My best guess is that there is a series of characters in one of the listings that breaks the xml.  But there is code that is supposed to clean it so it's actually very surprising that your getting this.

Are you trying to run this in a browser?  If so, it's possible that you might be running out of space to display it all and the xml string ends mid sentence.  Those are all guesses though.

I would try to pin point where exactly it breaks.  It works for limit=10 but does it work for limit=1000, limit=2000, etc?

If you can pinpoint that limit, then send though an offset to start at that listing-1 (listing minus one) and then limit=5 it.

If it still breaks, there is something funky in the listing data, if it works, it might be just a case of too much data.
Reply all
Reply to author
Forward
0 new messages