|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-04 20:19 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 08:00:02 2025 UTC |
Description: ------------ I've tried to write a document where a elements are in a namespace, but the namespace URI is only defined once in the root element. All other elements are written only with the mapped prefix. libxml2 allows namespaceURI to be null (i.e. in xmlTextWriterStartElementNS), which omits the xmlns attribute. But i.e. xmlwriter_write_element_ns or xmlwriter_start_element_ns in PHP convert null to an empty string, because zend_parse_parameters() is missing the ! for the namespace URI parameter. The only possible workaround is using xmlwriter_(start|create)_element and prepending the namespace prefix to the tagname "manually". Reproduce code: --------------- <?php // NOTE: results are indented for better readability $xml = new XmlWriter(); $xml->openMemory(); $xml->startDocument(); $xml->startElementNS('test', 'test', 'urn:x-test:'); $xml->writeElementNS('test', 'foo', null, ''); $xml->writeElementNS('test', 'bar', null, ''); $xml->endElement(); echo $xml->outputMemory(); ?> Expected result: ---------------- <?xml version="1.0"?> <test:test xmlns="urn:x-test:"> <test:foo></test:foo> <test:bar></test:bar> </test:test> Actual result: -------------- <?xml version="1.0"?> <test:test xmlns:test="urn:x-test:"> <test:foo xmlns:test=""></test:foo> <test:bar xmlns:test=""></test:bar> </test:test>