delirium Posted May 14, 2007 Share Posted May 14, 2007 I'm working on a class to parse XML and am having a frustrating time figuring out why the value of one of my class variables is disappearing. Here is a class I made to test the problem: class Parser { var $insideq; var $tag=""; var $qtext=""; var $num=0; function startElement($parser,$tagname,$attr) { $this->tag=$tagname; echo $tagname . "<br>"; echo $this->qtext; } function characterData($parser, $data) { if ($this->tag=="TEXT") { $this->qtext=$data; $this->num=1; } echo $this->qtext; echo $this->num; } function endElement($parser,$tagname) { if ($tagname=="SELECTONE") { echo $this->qtext; } echo "\\" . $tagname . "<br>"; } } Here is the XML that is being used to test: <SELECTONE> <TEXT>Testing text</TEXT> <punch></punch> <PUNCH></PUNCH> <PUNCH></PUNCH> </SELECTONE> And the output is as follows: SELECTONE 0TEXT Testing text1Testing text\TEXT 1PUNCH \PUNCH 1PUNCH \PUNCH 1PUNCH \PUNCH 1 \SELECTONE The program should be printing the value of $qtext ("Testing text") at the closing of each tag. Instead, it only seems to be storing the string for the duration of the Text tag and then prints blank for the rest of the tags. It has no problem remembering the value of $num, which leads me to believe there's something quirky about the $data variable in the characterData function (which is a character data handler function used like this - xml_set_character_data_handler($xml_parser, "characterData"); I'm clearly screwing something up, but I'm completely baffled as to what it is. Quote Link to comment https://forums.phpfreaks.com/topic/51343-xml-parsing-class-possible-scope-problem/ Share on other sites More sharing options...
delirium Posted May 16, 2007 Author Share Posted May 16, 2007 bump. anyone have an idea of what could be happening here? Quote Link to comment https://forums.phpfreaks.com/topic/51343-xml-parsing-class-possible-scope-problem/#findComment-254503 Share on other sites More sharing options...
delirium Posted May 21, 2007 Author Share Posted May 21, 2007 One last bump before I give up. Am I doing anything fundamentally wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/51343-xml-parsing-class-possible-scope-problem/#findComment-258233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.