Jump to content

simplexml_load_file errors: How Do Plan for Bad XML?


mtorbin

Recommended Posts

I have a process that I've build which will load multiple XML documents into memory using simplexml_load_file.  The problem is that some of the documents contain data that is screwy.  Specifically, we have file URLs that contain +, ˙ and & which obviously causes the simplexml_load_file to fail.  Any suggestions on this?  Modifying the XML before simplexml_load_file is not an option because we're downloading it from a vendor site.

 

Thanks,

 

- MT

Link to comment
Share on other sites

Modifying it is an option as the xml can be read into a variable prior to being used with simpleXML.

For this you will not make use of simplexml_load_file() but simplexml_load_string()

 

Read the contents of the xml file into a variable.

Scan for any bad characters and remove.

Pass the cleaned xml ino simplexml_load_string()

 

Also XML that contains HTML markup should be contained in a CDATA node. You could specify this in the simpleXML function parameter with the following constants http://uk3.php.net/manual/en/libxml.constants.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.