Bug in XMLWriter?

From: Date: Fri, 19 May 2006 18:36:04 +0000
Subject: Bug in XMLWriter?
Groups: php.general 
Request: Send a blank email to php-general+get-236513@lists.php.net to get a copy of this message
I am using XMLWriter with PHP 5.1.4 and find that it doesn't behave as I expect. I am under the impressing that until I call 'endElement', I should be free to continue adding attributes to an opened element regardless of whether I have already added elements or text below it. Look at this sample code: <?php //-------------------------------------------------- // create an object to write to an in-memory buffer $XML = new XMLWriter(); $XML->openMemory(); // start new element and add 1 attribute $XML->startElement("a"); $XML->writeAttribute("href", "http://www.google.com"); // add a text node $XML->text("Google"); // add another attribute (DOES NOT WORK) $XML->writeAttribute("target", "_blank"); // add more text $XML->text(" Go There"); // end the element and output so we can see what we have $XML->endElement(); print htmlspecialchars($XML->outputMemory()); //-------------------------------------------------- ?> output: <a href="http://www.google.com">Google Go There</a> If you notice, the 'target="_blank"' attribute was silently ignored. However, if I move that statement above the ->text() method call, it will work as expected. Is this a bug or a feature I don't know about? Dante

« previous php.general (#236513) next »