php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41287 XmlWrite Namespace functions don't allow xmlns defintion to be optional
Submitted: 2007-05-04 17:19 UTC Modified: 2007-08-23 14:04 UTC
From: bugs dot php-0705 at nico dot edtinger dot at Assigned:
Status: Closed Package: XML Writer
PHP Version: 5.2.2 OS: irrelevant
Private report: No CVE-ID: None
 [2007-05-04 17:19 UTC] bugs dot php-0705 at nico dot edtinger dot at
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>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-04 20:19 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC