summaryrefslogtreecommitdiff
path: root/ext/xmlwriter
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2005-12-09 04:57:20 +0000
committerRob Richards <rrichards@php.net>2005-12-09 04:57:20 +0000
commitc98ef984d8c9d4e0f89e4d363e264c85bb7cff38 (patch)
tree55b56816fd783a4864fcf18a614cd20c571e6fb4 /ext/xmlwriter
parent6b86285dd24321e579e5c6008b4c47d519083ad0 (diff)
downloadphp-git-c98ef984d8c9d4e0f89e4d363e264c85bb7cff38.tar.gz
MFH: enable a few additional functions
- add tests
Diffstat (limited to 'ext/xmlwriter')
-rw-r--r--ext/xmlwriter/php_xmlwriter.c22
-rw-r--r--ext/xmlwriter/php_xmlwriter.h8
-rw-r--r--ext/xmlwriter/tests/006.phpt27
-rw-r--r--ext/xmlwriter/tests/007.phpt38
-rw-r--r--ext/xmlwriter/tests/008.phpt35
-rw-r--r--ext/xmlwriter/tests/009.phpt43
-rw-r--r--ext/xmlwriter/tests/OO_007.phpt39
-rw-r--r--ext/xmlwriter/tests/OO_008.phpt36
-rw-r--r--ext/xmlwriter/tests/OO_009.phpt44
9 files changed, 289 insertions, 3 deletions
diff --git a/ext/xmlwriter/php_xmlwriter.c b/ext/xmlwriter/php_xmlwriter.c
index f44a6b26fb..d773be3b4e 100644
--- a/ext/xmlwriter/php_xmlwriter.c
+++ b/ext/xmlwriter/php_xmlwriter.c
@@ -139,6 +139,7 @@ static zend_function_entry xmlwriter_functions[] = {
PHP_FE(xmlwriter_write_attribute, NULL)
#if LIBXML_VERSION > 20617
PHP_FE(xmlwriter_start_attribute_ns,NULL)
+ PHP_FE(xmlwriter_write_attribute_ns,NULL)
#endif
PHP_FE(xmlwriter_start_element, NULL)
PHP_FE(xmlwriter_end_element, NULL)
@@ -160,6 +161,12 @@ static zend_function_entry xmlwriter_functions[] = {
PHP_FE(xmlwriter_write_dtd, NULL)
PHP_FE(xmlwriter_start_dtd_element, NULL)
PHP_FE(xmlwriter_end_dtd_element, NULL)
+ PHP_FE(xmlwriter_write_dtd_element, NULL)
+#if LIBXML_VERSION > 20608
+ PHP_FE(xmlwriter_start_dtd_attlist, NULL)
+ PHP_FE(xmlwriter_end_dtd_attlist, NULL)
+ PHP_FE(xmlwriter_write_dtd_attlist, NULL)
+#endif
PHP_FE(xmlwriter_output_memory, NULL)
PHP_FE(xmlwriter_flush, NULL)
{NULL, NULL, NULL}
@@ -184,6 +191,7 @@ static zend_function_entry xmlwriter_class_functions[] = {
PHP_ME_MAPPING(writeAttribute, xmlwriter_write_attribute, NULL)
#if LIBXML_VERSION > 20617
PHP_ME_MAPPING(startAttributeNs, xmlwriter_start_attribute_ns,NULL)
+ PHP_ME_MAPPING(writeAttributeNs, xmlwriter_write_attribute_ns,NULL)
#endif
PHP_ME_MAPPING(startElement, xmlwriter_start_element, NULL)
PHP_ME_MAPPING(endElement, xmlwriter_end_element, NULL)
@@ -205,6 +213,12 @@ static zend_function_entry xmlwriter_class_functions[] = {
PHP_ME_MAPPING(writeDtd, xmlwriter_write_dtd, NULL)
PHP_ME_MAPPING(startDtdElement, xmlwriter_start_dtd_element, NULL)
PHP_ME_MAPPING(endDtdElement, xmlwriter_end_dtd_element, NULL)
+ PHP_ME_MAPPING(writeDtdElement, xmlwriter_write_dtd_element, NULL)
+#if LIBXML_VERSION > 20608
+ PHP_ME_MAPPING(startDtdAttlist, xmlwriter_start_dtd_attlist, NULL)
+ PHP_ME_MAPPING(endDtdAttlist, xmlwriter_end_dtd_attlist, NULL)
+ PHP_ME_MAPPING(writeDtdAttlist, xmlwriter_write_dtd_attlist, NULL)
+#endif
PHP_ME_MAPPING(outputMemory, xmlwriter_output_memory, NULL)
PHP_ME_MAPPING(flush, xmlwriter_flush, NULL)
{NULL, NULL, NULL}
@@ -338,7 +352,7 @@ static void xmlwriter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
/* }}} */
#if LIBXML_VERSION >= 20605
-/* {{{ proto bool xmlwriter_set_indent(resource xmlwriter, bool)
+/* {{{ proto bool xmlwriter_set_indent(resource xmlwriter, bool indent)
Toggle indentation on/off - returns FALSE on error */
PHP_FUNCTION(xmlwriter_set_indent)
{
@@ -628,6 +642,7 @@ PHP_FUNCTION(xmlwriter_write_attribute)
}
/* }}} */
+#if LIBXML_VERSION > 20617
/* {{{ proto bool xmlwriter_write_attribute_ns(resource xmlwriter, string prefix, string name, string uri, string content)
Write full namespaced attribute - returns FALSE on error */
PHP_FUNCTION(xmlwriter_write_attribute_ns)
@@ -671,6 +686,7 @@ PHP_FUNCTION(xmlwriter_write_attribute_ns)
RETURN_FALSE;
}
/* }}} */
+#endif
/* {{{ proto bool xmlwriter_start_element(resource xmlwriter, string name)
Create start element tag - returns FALSE on error */
@@ -1364,7 +1380,7 @@ PHP_FUNCTION(xmlwriter_write_dtd_element)
zval *this = getThis();
if (this) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
@@ -1393,6 +1409,7 @@ PHP_FUNCTION(xmlwriter_write_dtd_element)
}
/* }}} */
+#if LIBXML_VERSION > 20608
/* {{{ proto bool xmlwriter_start_dtd_attlist(resource xmlwriter, string name)
Create start DTD AttList - returns FALSE on error */
PHP_FUNCTION(xmlwriter_start_dtd_attlist)
@@ -1583,6 +1600,7 @@ PHP_FUNCTION(xmlwriter_write_dtd_entity)
RETURN_FALSE;
}
/* }}} */
+#endif
/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
Create new xmlwriter using source uri for output */
diff --git a/ext/xmlwriter/php_xmlwriter.h b/ext/xmlwriter/php_xmlwriter.h
index 12038e7f34..f27774da4c 100644
--- a/ext/xmlwriter/php_xmlwriter.h
+++ b/ext/xmlwriter/php_xmlwriter.h
@@ -63,9 +63,9 @@ PHP_FUNCTION(xmlwriter_set_indent_string);
#endif
PHP_FUNCTION(xmlwriter_start_attribute);
PHP_FUNCTION(xmlwriter_end_attribute);
-PHP_FUNCTION(xmlwriter_start_attribute_ns);
PHP_FUNCTION(xmlwriter_write_attribute);
#if LIBXML_VERSION > 20617
+PHP_FUNCTION(xmlwriter_start_attribute_ns);
PHP_FUNCTION(xmlwriter_write_attribute_ns);
#endif
PHP_FUNCTION(xmlwriter_start_element);
@@ -92,6 +92,12 @@ PHP_FUNCTION(xmlwriter_end_dtd);
PHP_FUNCTION(xmlwriter_write_dtd);
PHP_FUNCTION(xmlwriter_start_dtd_element);
PHP_FUNCTION(xmlwriter_end_dtd_element);
+PHP_FUNCTION(xmlwriter_write_dtd_element);
+#if LIBXML_VERSION > 20608
+PHP_FUNCTION(xmlwriter_start_dtd_attlist);
+PHP_FUNCTION(xmlwriter_end_dtd_attlist);
+PHP_FUNCTION(xmlwriter_write_dtd_attlist);
+#endif
PHP_FUNCTION(xmlwriter_open_uri);
PHP_FUNCTION(xmlwriter_open_memory);
PHP_FUNCTION(xmlwriter_output_memory);
diff --git a/ext/xmlwriter/tests/006.phpt b/ext/xmlwriter/tests/006.phpt
new file mode 100644
index 0000000000..3b290ad2d2
--- /dev/null
+++ b/ext/xmlwriter/tests/006.phpt
@@ -0,0 +1,27 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, startDTD/writeElementNS
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_uri($doc_dest);
+xmlwriter_start_dtd($xw, 'foo', NULL, 'urn:bar');
+xmlwriter_end_dtd($xw);
+xmlwriter_start_element($xw, 'foo');
+xmlwriter_write_element_ns($xw, 'foo', 'bar', 'urn:foo', 'dummy content');
+xmlwriter_end_element($xw);
+
+// Force to write and empty the buffer
+$output_bytes = xmlwriter_flush($xw, true);
+echo file_get_contents($doc_dest);
+unset($xw);
+unlink('001.xml');
+?>
+--EXPECT--
+<!DOCTYPE foo SYSTEM "urn:bar"><foo><foo:bar xmlns:foo="urn:foo">dummy content</foo:bar></foo>
diff --git a/ext/xmlwriter/tests/007.phpt b/ext/xmlwriter/tests/007.phpt
new file mode 100644
index 0000000000..2e6ad3c54d
--- /dev/null
+++ b/ext/xmlwriter/tests/007.phpt
@@ -0,0 +1,38 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, Elements & Attributes
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_set_indent_string($xw, ' ');
+xmlwriter_start_document($xw, '1.0', "UTF-8");
+xmlwriter_start_element($xw, 'root');
+xmlwriter_start_element_ns($xw, 'ns1', 'child1', 'urn:ns1');
+xmlwriter_start_attribute_ns($xw, 'ns1', 'att1', 'urn:ns1');
+xmlwriter_text($xw, 'a&b');
+xmlwriter_end_attribute($xw);
+xmlwriter_write_attribute($xw, 'att2', "double\" single'");
+xmlwriter_start_attribute_ns($xw, 'ns1', 'att2', 'urn:ns1');
+xmlwriter_text($xw, "<>\"'&");
+xmlwriter_end_attribute($xw);
+xmlwriter_write_element($xw, 'chars', "special characters: <>\"'&");
+xmlwriter_end_element($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <ns1:child1 xmlns:ns1="urn:ns1" ns1:att1="a&amp;b" xmlns:ns1="urn:ns1" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
+ <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
+ </ns1:child1>
+</root>
diff --git a/ext/xmlwriter/tests/008.phpt b/ext/xmlwriter/tests/008.phpt
new file mode 100644
index 0000000000..17e0eab5fa
--- /dev/null
+++ b/ext/xmlwriter/tests/008.phpt
@@ -0,0 +1,35 @@
+--TEST--
+XMLWriter: libxml2 XML Writer DTD Element & Attlist
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_start_document($xw, NULL, "UTF-8");
+xmlwriter_write_dtd_element($xw, 'sxe', '(elem1+, elem11, elem22*)');
+xmlwriter_write_dtd_attlist($xw, 'sxe', 'id CDATA #implied');
+xmlwriter_start_dtd_element($xw, 'elem1');
+xmlwriter_text($xw, 'elem2*');
+xmlwriter_end_dtd_element($xw);
+xmlwriter_start_dtd_attlist($xw, 'elem1');
+xmlwriter_text($xw, "attr1 CDATA #required\n");
+xmlwriter_text($xw, 'attr2 CDATA #implied');
+xmlwriter_end_dtd_attlist($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<!ELEMENT sxe (elem1+, elem11, elem22*)>
+<!ATTLIST sxe id CDATA #implied>
+<!ELEMENT elem1 elem2*>
+<!ATTLIST elem1 attr1 CDATA #required
+attr2 CDATA #implied>
diff --git a/ext/xmlwriter/tests/009.phpt b/ext/xmlwriter/tests/009.phpt
new file mode 100644
index 0000000000..2322b7c0ba
--- /dev/null
+++ b/ext/xmlwriter/tests/009.phpt
@@ -0,0 +1,43 @@
+--TEST--
+XMLWriter: PI, Comment, CDATA
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_start_document($xw, NULL, "UTF-8");
+xmlwriter_start_element($xw, 'root');
+xmlwriter_write_attribute($xw, 'id', 'elem1');
+xmlwriter_start_element($xw, 'elem1');
+xmlwriter_write_attribute($xw, 'attr1', 'first');
+xmlwriter_write_comment($xw, 'start PI');
+xmlwriter_start_element($xw, 'pi');
+xmlwriter_write_pi($xw, 'php', 'echo "hello world"; ');
+xmlwriter_end_element($xw);
+xmlwriter_start_element($xw, 'cdata');
+xmlwriter_start_cdata($xw);
+xmlwriter_end_element($xw);
+xmlwriter_text($xw, '<>&"');
+xmlwriter_end_cdata($xw);
+xmlwriter_end_element($xw);
+xmlwriter_end_element($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root id="elem1">
+ <elem1 attr1="first">
+ <!--start PI-->
+ <pi><?php echo "hello world"; ?></pi>
+ <cdata><![CDATA[<>&"]]></cdata>
+ </elem1>
+</root>
diff --git a/ext/xmlwriter/tests/OO_007.phpt b/ext/xmlwriter/tests/OO_007.phpt
new file mode 100644
index 0000000000..119be93111
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_007.phpt
@@ -0,0 +1,39 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, Elements & Attributes
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->setIndentString(' ');
+$xw->startDocument('1.0', "UTF-8");
+$xw->startElement('root');
+$xw->startElementNS('ns1', 'child1', 'urn:ns1');
+$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
+$xw->text('a&b');
+$xw->endAttribute();
+$xw->writeAttribute('att2', "double\" single'");
+$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
+$xw->text("<>\"'&");
+$xw->endAttribute();
+$xw->writeElement('chars', "special characters: <>\"'&");
+$xw->endElement();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <ns1:child1 xmlns:ns1="urn:ns1" ns1:att1="a&amp;b" xmlns:ns1="urn:ns1" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
+ <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
+ </ns1:child1>
+</root>
diff --git a/ext/xmlwriter/tests/OO_008.phpt b/ext/xmlwriter/tests/OO_008.phpt
new file mode 100644
index 0000000000..ee555986ff
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_008.phpt
@@ -0,0 +1,36 @@
+--TEST--
+XMLWriter: libxml2 XML Writer DTD Element & Attlist
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->startDocument(NULL, "UTF-8");
+$xw->writeDtdElement('sxe', '(elem1+, elem11, elem22*)');
+$xw->writeDtdAttlist('sxe', 'id CDATA #implied');
+$xw->startDtdElement('elem1');
+$xw->text('elem2*');
+$xw->endDtdElement();
+$xw->startDtdAttlist('elem1');
+$xw->text("attr1 CDATA #required\n");
+$xw->text('attr2 CDATA #implied');
+$xw->endDtdAttlist();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<!ELEMENT sxe (elem1+, elem11, elem22*)>
+<!ATTLIST sxe id CDATA #implied>
+<!ELEMENT elem1 elem2*>
+<!ATTLIST elem1 attr1 CDATA #required
+attr2 CDATA #implied>
diff --git a/ext/xmlwriter/tests/OO_009.phpt b/ext/xmlwriter/tests/OO_009.phpt
new file mode 100644
index 0000000000..659cfc8d6d
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_009.phpt
@@ -0,0 +1,44 @@
+--TEST--
+XMLWriter: PI, Comment, CDATA
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->startDocument("1.0", "UTF-8");
+$xw->startElement('root');
+$xw->writeAttribute('id', 'elem1');
+$xw->startElement('elem1');
+$xw->writeAttribute('attr1', 'first');
+$xw->writeComment('start PI');
+$xw->startElement('pi');
+$xw->writePi('php', 'echo "hello world"; ');
+$xw->endElement();
+$xw->startElement('cdata');
+$xw->startCdata();
+$xw->endElement();
+$xw->text('<>&"');
+$xw->endCdata();
+$xw->endElement();
+$xw->endElement();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root id="elem1">
+ <elem1 attr1="first">
+ <!--start PI-->
+ <pi><?php echo "hello world"; ?></pi>
+ <cdata><![CDATA[<>&"]]></cdata>
+ </elem1>
+</root>