Re: XML_Tree doctype patch
| From: | Tomas V.V.Cox | Date: | Wed, 27 Aug 2003 11:37:02 +0000 |
| Subject: | Re: XML_Tree doctype patch | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20622@lists.php.net to get a copy of this message | ||
Thanks I'll take care on it.
Tomas V.V.Cox
On Monday, August 25, 2003 23:15, Aaron S. Hawley wrote:
> There's no way to squeeze in a DOCTYPE tag in when using XML_Tree to
> create XML content. (Of course, the parser doesn't keep track of it
> either. hopefully in the next release of expat.).
> This patch provides the following:
> <?php
> require_once 'XML/Tree.php';
> $doctype = "html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n
>
> \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"";
> $tree = new XML_Tree(null, '1.0', $doctype);
$html =& $tree->>addRoot('html');
$head =& $html->>addChild('head');
$head->>addChild('title', 'My XHTML Page');
$body =& $html->>addChild('body');
$body->>addChild('p', 'A paragraph.');
print $tree->>dump();
?>>
> Giving the output:
> <?xml version="1.0"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
>
> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
> <html>
> <head>
> <title>My XHTML Page</title>
> </head>
> <body>
> <p>A paragraph.</p>
> </body>
> </html>
> Note: The patch also now modifies the XML version behavior by having an
> empty() version variable fail to print the XML tag (<?xml ?>) at all.
> Index: XML_Tree/Tree.php
> ===================================================================
> RCS file: /repository/pear/XML_Tree/Tree.php,v
> retrieving revision 1.27
> diff -u -u -r1.27 Tree.php
> --- XML_Tree/Tree.php 11 Jul 2003 00:58:30 -0000 1.27
> +++ XML_Tree/Tree.php 25 Aug 2003 20:51:47 -0000
> @@ -42,7 +42,7 @@
> *
> * $tree->dump(true);
> *
> -* @author Bernd Römer <berndr@bonn.edu>
> +* @author Bernd Römer <berndr@bonn.edu>
> * @package XML
> * @version $Version$ - 1.0
> */
> @@ -84,15 +84,23 @@
> var $version = '1.0';
> /**
> + * Doctype
> + *
> + * @var string
> + */
> + var $doctype = '';
> +
> + /**
> * Constructor
> *
> * @param string filename Filename where to read the XML
> * @param string version XML Version to apply
> */
> - function XML_Tree($filename = '', $version = '1.0')
> + function XML_Tree($filename = '', $version = '1.0', $doctype =
> '')
> {
> $this->filename = $filename;
> $this->version = $version;
+ $this->>doctype = $doctype;
> }
> /**
> @@ -392,6 +400,10 @@
> */
> function &get()
> {
> + $out = empty($this->version) ? ""
> + : "<?xml version=\"{$this->version}\"?>\n";
> + $out .= empty($this->doctype) ? ""
> + : "<!DOCTYPE {$this->doctype}>\n";
> $out = '<?xml version="' . $this->version .
> "\"?>\n";
> if (!is_null($this->root))
> {
--
Tomas V.V.Cox mailto:cox@idecnet.com