xmlwriter_write_raw() not in 5.1.4 yet?

php.internals

D. Dante Lorenso

20 years ago
I'm on the latest and greatest PHP 5.1.4. I can see the function I think I want in the manual: http://us3.php.net/manual/en/function.xmlwriter-write-raw.php But the manual says it's only in CVS. I confirmed that I don't have it: * Fatal error: Call to undefined function xmlwriter_write_raw() in ***.php on line ** I am hoping that this function would let me merge already-created XML into the XML I am writing and avoid the <, >, &, etc escaping of content which is normally done when using xmlwriter_text(). Zend summary was talking about it back in December. We've had a couple version updates since then. Still not in the official release? * http://www.zend.com/zend/week/week268.php#Heading8 Anyone know the status of this function, if it does what I want, and what version I can start using it? Dante

Jared Williams

20 years ago
> > I'm on the latest and greatest PHP 5.1.4. I can see the > function I think I want in the manual: > > http://us3.php.net/manual/en/function.xmlwriter-write-raw.php > > But the manual says it's only in CVS. I confirmed that I > don't have it: > > * Fatal error: Call to undefined function xmlwriter_write_raw() in > ***.php on line ** > > I am hoping that this function would let me merge > already-created XML into the XML I am writing and avoid the > <, >, &, etc escaping of content which is normally done when > using xmlwriter_text(). Zend summary was talking about it > back in December. We've had a couple version updates since > then. Still not in the official release? > > * http://www.zend.com/zend/week/week268.php#Heading8 > > Anyone know the status of this function, if it does what I > want, and what version I can start using it? >
I originally requested it. http://pecl.php.net/bugs/bug.php?id=6267 . I think it'll appear in 5.2, http://oss.backendmedia.com/PhP52 . Jared

D. Dante Lorenso

20 years ago
Jared Williams wrote:
>> http://us3.php.net/manual/en/function.xmlwriter-write-raw.php >> >> Anyone know the status of this function, if it does what I >> want, and what version I can start using it? > I originally requested it. http://pecl.php.net/bugs/bug.php?id=6267 . I think it'll appear in 5.2, > http://oss.backendmedia.com/PhP52 . Jared
Let me double-check that this does what I think it does. Take this code for example: <?php //-------------------------------------------------- // build <img src="http://us2.php.net/images/php.gif" width="120" height="67"/> $I = xmlwriter_open_memory(); xmlwriter_start_element($I, "img"); xmlwriter_write_attribute($I, "src", "http://us2.php.net/images/php.gif"); xmlwriter_write_attribute($I, "width", "120"); xmlwriter_write_attribute($I, "height", "67"); xmlwriter_end_element($I); $IMG_XHTML = xmlwriter_output_memory($I); // build <a href="http://www.php.net">{REPLACE_ME}</a> $A = xmlwriter_open_memory(); xmlwriter_start_element($A, "a"); xmlwriter_write_attribute($A, "href", "http://www.php.net/"); xmlwriter_text($A, "{REPLACE_ME}"); xmlwriter_end_element($A); $A_XHTML = xmlwriter_output_memory($A); // merge XML parts together $xml_str = str_replace("{REPLACE_ME}", $IMG_XHTML, $A_XHTML); print htmlspecialchars($xml_str); // <a href="http://www.php.net/"><img src="http://us2.php.net/images/php.gif" width="120" height="67"/></a> //-------------------------------------------------- ?> Instead of having to merge the two XML strings back together, I could write something like this instead?: <?php //-------------------------------------------------- // build <img src="http://us2.php.net/images/php.gif" width="120" height="67"/> $I = xmlwriter_open_memory(); xmlwriter_start_element($I, "img"); xmlwriter_write_attribute($I, "src", "http://us2.php.net/images/php.gif"); xmlwriter_write_attribute($I, "width", "120"); xmlwriter_write_attribute($I, "height", "67"); xmlwriter_end_element($I); $IMG_XHTML = xmlwriter_output_memory($I); // build <a href="http://www.php.net">$IMG_XHTML</a> $A = xmlwriter_open_memory(); xmlwriter_start_element($A, "a"); xmlwriter_write_attribute($A, "href", "http://www.php.net/"); xmlwriter_write_raw($A, $IMG_XHTML); // merge already created XML xmlwriter_end_element($A); $xml_str = xmlwriter_output_memory($A); // merge already done print htmlspecialchars($xml_str); // <a href="http://www.php.net/"><img src="http://us2.php.net/images/php.gif" width="120" height="67"/></a> //-------------------------------------------------- ?> I know this example is a little silly since a merge would never have been necessary, but in my current code, I often construct parts of XML documents inside other classes which need to all be stitched back together to yield the final XHTML output. Being able to write 'raw' XHTML into an existing node is helpful. Documentation on XMLWriter is very sketchy overall. Looking at the extension source, I see that I can use this as an object 'new XMLWriter', but the documentation doesn't say anything about that. When I wrap this functionality into my own custom XWriter object, I can create shorthand like this: <?php //-------------------------------------------------- $XML = new XWriter("a", "href", "http://www.php.net"); $XML->append("img", "src", "http://us2.php.net/images/php.gif", "width", "120", "height", "67"); $xml_str = $XML->toXML(); //-------------------------------------------------- ?> I'll be writing an article on XWriter some time in the next month on my blog, but I need to use XWriter to create the blog software, first ;-) Having the ability to xmlwriter_write_raw() would be a big help in making XWriter more efficient. Dante