XML Parsing - Tag contents are split at apostrophes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IMJackson
Forum Newbie
Posts: 1
Joined: Wed Aug 15, 2007 8:35 am

XML Parsing - Tag contents are split at apostrophes

Post by IMJackson »

Hi,

I'm currently trying to write some code to parse an RSS news feed, using the standard XML Parser functions (the site I am working on must run on a PHP4 server, hence no SimpleXML, unfortunately).

I have got the parser and all its handlers essentially working. However, I have found that when the contents of a tag are passed to the character data handler, if there is an apostrophe then the contents will be split up, resulting in multiple calls to the handler. For example:

Code: Select all

<title>House plans &apos;will hit green belt&apos;</title>
If I output the individual pieces of data passed to the character data handler for the above snippet of XML to an array, the result is:

Code: Select all

[0] => House plans
[1] => '
[2] => will hit green belt
[3] => '
This also appears to occur with other special characters, such as quotes (") or pound signs (£). I want the entire contents of the tag to be passed to the handler in one go, not piece-by-piece as above. I've tried searching on Google but I can't find any explanation for this behaviour. Could someone please help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Entities, those special marks, are separate pieces of data. They sometimes need to be handled separately and specifically. That is why you are getting it separated.
Post Reply