Re: Simple XML - problem with errors
| From: | Richard Quadling | Date: | Thu, 08 Jul 2010 10:54:29 +0000 |
| Subject: | Re: Simple XML - problem with errors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306756@lists.php.net to get a copy of this message | ||
On 8 July 2010 08:07, Gary . <php-general@garydjones.name> wrote:
> Why am I still getting an exception when I do this:
>
> libxml_use_internal_errors(true);
> $this->xml = new SimpleXMLElement($this->htmlString);
>
> or this
> $this->xml = new SimpleXMLElement($this->htmlString,
> LIBXML_NOERROR|LIBXML_NOWARNING);
>
> ?
>
> The exception says "Exception: String could not be parsed as XML". Not
> a hint of why not, of course.
>
> I thought the point of those things was to just stuff the content in,
> and let user code handle errors? I mean, I *know* the provided HTML is
> broken. I also know there's not a chance in hell of it ever being
> fixed (completely out of my control).
>
> And yes, I'd rather use DOM, but I can't.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
The XML needs to be "well formed" [1]. So, if it is junk, you can't
read it using SimpleXML as the XML is not well formed.
Try putting it through Tidy first - that is, tidy the file first.
Regards,
Richard.
[1] http://www.devx.com/projectcool/Article/19944/0/page/3