I too love the undocumented "splitting" functionality :-p.
Rather than concatinating the data based on whether or not the current tag name has changed from the previous tag name I suggest always concatinating like the following with the $catData variable being unset in the endElement function:
<?php
function endElement ($parser, $data) {
global $catData;
// Because we are at an element end we know any splitting is finished
unset($GLOBALS['catData']);
}
function characterData ($parser, $data) {
global $catData;
// Concatinate data in case splitting is taking place
$catData.=$data;
}
?>
This got me around a problem with data like the following where, because characterData is not called for empty tags, the previous and current tag names were the same even though splitting was not taking place.
<companydept>
<companydeptID></companydeptID>
<companyID>1</companyID>
<companydeptName></companydeptName>
</companydept>
<companydept>
<companydeptID></companydeptID>
<companyID>2</companyID>
<companydeptName></companydeptName>
</companydept>
<companydept>
<companydeptID></companydeptID>
<companyID>3</companyID>
<companydeptName></companydeptName>
</companydept>