Error Loading Xml Markup Phpquery
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Alternative to phpQuery that doesn't crash when dealing with invalid markup? up vote 1 down vote favorite I am using phpQuery to parse pages however I noticed that when using it with pages with invalid markup it results to PHP Fatal error: Uncaught exception 'Exception' with message 'Error loading XML markup' An example offending code in a page is: I wish phpQuery would return false for such pages but sadly it results in instant fatal error preventing me to do something about it. The error happens immediately upon initializing phpquery like phpQuery::newDocumentFile($page); I really like phpQuery since it works like jQuery but I'm looking for an alternative solution that works on invalid markups. php regex screen-scraping share|improve this question edited Mar 22 '12 at 18:30 Josh 5,80542536 asked Mar 22 '12 at 18:28 IMB 2,37773065 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted Actually, the crash isn't caused because of the invalid markup. The crash is caused becase you don't catch the exception that the invalid markup throws. Try initializing in a try-catch like: try { phpQuery::newDocumentFile($page); //Process the page here } catch (Exception $e) { //What do we do if any of that fails? } Exceptions only become fatal errors if you don't catch them. share|improve this answer edited Mar 22 '12 at 18:40 answered Mar 22 '12 at 18:33 OhCaN 1,412821 Catching the exception is also a good approach. –Mike Purcell Mar 22 '12 at 18:40 add a comment| Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example). Subscribed! Success! Please click the link in the co
Downloader (bookmark) Get current weather forecast using PHPQuery December 17th, 2013 by Alex Leave a reply » // load PHPQuery require_once 'phpquery.php'; // load URL and parse it with PHPQuery $html = file_get_contents('http://www.accuweather.com/en/ua/kiev/324505/weather-forecast/324505'); phpQuery::newDocumentHTML($html); // and now just output the data foreach(pq('#feed-main') as $feed) { echo 'Condition: '.pq($feed)->find('.cond')->text() . '
'; echo 'Temperature: '.pq($feed)->find('.temp')->text() . '
'; } This would output something like Condition: Light Fog
Temperature: 1°
If you get a "Fatal error: Uncaught exception ‘Exception' with message ‘Error loading XML markup'" then you are probably trying to load an XHTML document with http://stackoverflow.com/questions/9828322/alternative-to-phpquery-that-doesnt-crash-when-dealing-with-invalid-markup phpQuery::newDocumentHTML or opposite. Just try using phpQuery::newDocumentXHTML or phpQuery::newDocumentXML. This page can be found by searching for:phpQueryRelated NotesConvert RGB to HSL in PHP, and sort by colorA (very) simple example of parsing HTML document or string with PHPQueryExcel and UTF-8 CSV exportPHP strtotime cheatsheetConfiguring Sendmail to send with GMail in XAMPP Previous Entry: A (very) simple example of parsing HTML document or string http://graphicmaniacs.com/note/get-current-weather-forecast-using-phpquery/ with PHPQuery Next Entry: Display and hide a block using jQuery Posted in PHP You can follow any responses to this entry through the RSS 2.0 Feed. Both comments and pings are currently closed. Comments are closed. Online Development Tools Previous Entry A (very) simple example of parsing HTML document or string with PHPQuery Next Entry Display and hide a block using jQuery Feeds Fresh Notes Get a random ID string in MongoDB Test server Accept-Range with cURL Enable Apache2 mod_rewrite on Linux Download all images from current page with JavaScript Adding a message with JavaScript before leaving the page Searching for a value in a combined MySQL column Convert RGB to HSL in PHP, and sort by color Fresh CommentsStRiKeR on MyIP Google Chrome Pluginmanyanimals on VideoGrab – Google Chrome ExtensionAlex on Use FB.ui() instead of old Facebook sharerToni on Use FB.ui() instead of old Facebook sharerxbox360 on Adding a message with JavaScript before leaving the pageElias on MyIP Google Chrome PluginAlex on Searching for a value in a combined MySQL column Categories Apps (3) CSS (15) Flash (3) Graphics (19) HTML (11) JavaScript (31) Misce
that make connections all over the world. Join today Download & Extend Drupal Core Distributions Modules Themes Single Page WebsiteIssues Text encoding not https://www.drupal.org/node/1382020 correct Closed (fixed)Project:Single Page WebsiteVersion:7.x-2.0-beta3Component:CodePriority:MajorCategory:Bug reportAssigned:UnassignedReporter:germaike mvCreated:December 23, 2011 - 14:20Updated:March 13, 2012 - 20:40 Log in or register to update this issue If i enter text into a http://code.simcu.com/xrain0610/gitblog/blob/a061e4a46499c5c8022b70df65d8bb7a65f808ee/app/third_party/phpQuery/phpQuery/DOMDocumentWrapper.php new basic page, it is perfectly rendered in the normal drupal pages. When i view the single page, i get weird characters? I attached 2 screenshots with the error loading differents between the single page and the edit page of drupal. Kind regardsFiles: CommentFileSizeAuthor Screen single page403.58 KBgermaike mv screen in edit376.99 KBgermaike mv Comments Comment #1 germaike mv CreditAttribution: germaike mv commented December 23, 2011 at 2:43pm Find a solution for this problem : Replace line 58-59 with: $document = phpQuery::newDocumentXHTML($content); $output .= $document->find(variable_get('single_page_website_content', '#content .content'))->htmlOuter(); Now error loading xml the text is rendered as XHTML and isn't giving anymore weird characters. Log in or register to post comments Comment #2 jamiehollern CreditAttribution: jamiehollern commented December 28, 2011 at 3:03pm When I try germaike mv's solution, I receive this error: Exception: Error loading XML markup in DOMDocumentWrapper->loadMarkupXML() (line 424 of /sites/all/libraries/phpQuery/phpQuery-onefile.php). Edit: I believe this is to do with a bug in PHPQuery. Log in or register to post comments Comment #3 jamiehollern CreditAttribution: jamiehollern commented December 28, 2011 at 3:22pm For some reason, on line 83 of single_page_website.module if you change return $output; to this return utf8_decode($output); it seems to partially work. The function changes the variable $output from UTF-8 to ISO-8859-1, but the output should work as UTF-8. Log in or register to post comments Comment #4 germaike mv CreditAttribution: germaike mv commented January 5, 2012 at 10:38am This also seems to work. Thx Log in or register to post comments Comment #5 Yaremchuk CreditAttribution: Yaremchuk commented February 28, 2012 at 8:38pm Status: Active » Fixed Please use http://php.sfdev.com.s3.amazonaws.com/phpQuery-onefile.php.gz
0 Network Create a new issue Builds Commits Files Commits Network Compare Branches Tags a061e4a46499c5c8022b70df65d8bb7a65f808ee Switch branch/tag gitblog app third_party phpQuery phpQuery DOMDocumentWrapper.php update · a061e4a4 ... a061e4a4 1.优化了博客属性的提取,采用正则,减少代码 2.summary属性支持多行 3.支持wordpress导入 4.SEO优化 5.新增主题line 6.删除一些无用的代码和注释 jockchou authored 2015-08-04 18:55:04 +0800 DOMDocumentWrapper.php 22.4 KB Raw Blame History Permalink 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 50