Re: Bug in XMLWriter?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Expected behavior. See comments within code snippet.

D. Dante Lorenso wrote:
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");

Here you just closed the starting element tag and moved into content.


// add another attribute (DOES NOT WORK)
$XML->writeAttribute("target", "_blank");

If you check the return value (FALSE), you will see it failed.
The writer is positioned within element content so cannot write an attribute. Attributes must be written while still positioned within the element's start tag.

Rob

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux