[PHP] Re: xml_set_character_data_handler logic

2002-09-30 Thread Leendert Brouwer

Cardinal from IRC answered my question. It turns out that when you indent
your childs with tabs, it sees those tabs as cdata of the root element. I
had the following XML file:

sampleDBName
sampleUser
localhost


The tabs in front of the child elements were treated as CDATA of the
 root node.


"Leendert" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> "Leendert" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > It appears that:
> >
> > xml_set_character_data_handler($parser, 'handleData');
> >
> > calls handleData() 3 times per element. Does anyone know the reason
behind
> > this? Sounds like that could be very inefficient.
> >
> >
>
> FYI, this is the code I'm using:
>
>  class XMLSettingsParser
> {
>  var $settingsFile;
>  var $xmlData;
>  var $parser;
>  var $tempElementName;
>
>  function XMLSettingsParser($settingsFile)
>  {
>   $this->SettingsFile = $settingsFile;
>
>   $this->xmlData = implode('', file($settingsFile));
>
>   $this->parser = xml_parser_create();
>   xml_set_object($this->parser, &$this);
>
>   xml_set_element_handler($this->parser, 'handleStartElement',
> 'handleEndElement');
>   xml_set_character_data_handler($this->parser, 'handleData');
>
>   xml_parse($this->parser, $this->xmlData);
>   xml_parser_free($this->parser);
>  }
>
>  function handleStartElement($parser, $name, $attribs)
>  {
>   $this->tempElementName = $name;
>  }
>
>  function handleEndElement()
>  {}
>
>  function handleData($parser, $data)
>  {
>   //if(!defined($this->tempElementName))
>define($this->tempElementName, $data);
>  }
> }
> ?>
>
> It gives me 2 notices per element that the constant is already defined,
> while it shouldn't. When I do use the conditional
> if(!defined($this->tempElementName))  it works fine of course. But it
should
> work in the first place.
> Note: you need error_reporting(E_NOTICE); on to see the error.
>
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: [PHP-DEV] toString() in SimpleXML?

2005-02-17 Thread Leendert Brouwer
Hi Marcus,
Marcus Boerger wrote:
  having a function __toString() would interfere with the mapping ideas of
SimpleXML. However it is there internally so you simply do one of the
following:
php -r '$x=SimpleXML_load_string("blablabla"); echo 
$x, "\n"; var_dump((string)$x);'
I'm aware of that. But how would something like nodeValue() interfere 
with the mapping ideas behind SimpleXML? IMHO, casts are not intuitive 
in a development process, especially not when you need them as much as 
you would in SimpleXML. Now it just feels like working around a problem 
when coding.

further questions please to [EMAIL PROTECTED]
as you wish..
Monday, February 14, 2005, 1:23:44 PM, you wrote:

Hi,

I have a feature request. Maybe it would be a good idea to have a 
toString() or perhaps nodeValue() method in SimpleXML's SimpleXMLElement 
class? It might make it more obvious that the element is still a 
SimpleXMLElement object when you want to actually use it (when you print 
it, the value automagically casts to a string internally, so users might 
think that it will be casted to a string when you directly access it 
without a specified property/method, which is not the case). I know that 
the docs say that you should cast it to a string when you want to do a 
comparison, but apart from that just being an example, maybe my 
suggestion is a more obvious one to notice?

regards,

Leendert



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php