cvs: pear /XML_Beautifier/Beautifier Tokenizer.php /XML_Beautifier/Beautifier/Renderer Plain.php /XML_Beautifier/examples example2.php test.xml
test2.xml

From: Date: Sat, 17 Apr 2004 09:01:29 +0000
Subject: cvs: pear /XML_Beautifier/Beautifier Tokenizer.php /XML_Beautifier/Beautifier/Renderer Plain.php /XML_Beautifier/examples example2.php test.xml
test2.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-18336@lists.php.net to get a copy of this message
schst Sat Apr 17 05:01:29 2004 EDT Modified files: /pear/XML_Beautifier/Beautifier/Renderer Plain.php /pear/XML_Beautifier/Beautifier Tokenizer.php /pear/XML_Beautifier/examples example2.php test.xml test2.xml Log: added support for CData sections (bug #1009)

http://cvs.php.net/diff.php/pear/XML_Beautifier/Beautifier/Renderer/Plain.php?r1=1.4&r2=1.5&ty=u Index: pear/XML_Beautifier/Beautifier/Renderer/Plain.php diff -u pear/XML_Beautifier/Beautifier/Renderer/Plain.php:1.4 pear/XML_Beautifier/Beautifier/Renderer/Plain.php:1.5 --- pear/XML_Beautifier/Beautifier/Renderer/Plain.php:1.4 Sun Feb 1 16:45:44 2004 +++ pear/XML_Beautifier/Beautifier/Renderer/Plain.php Sat Apr 17 05:01:27 2004 @@ -41,8 +41,7 @@ * @package XML_Beautifier * @author Stephan Schmidt <schst@php.net> * @todo option to specify inline tags - * @todo option to specify treatment of whitespac in data sections - * @todo automatically create <![CDATA[ ]]> sections + * @todo option to specify treatment of whitespace in data sections */ class XML_Beautifier_Renderer_Plain extends XML_Beautifier_Renderer { @@ -120,7 +119,7 @@ { $data = "\n" . $this->_indentTextBlock( $data, $token['depth']+1, true ); } - + $xml = $indent . XML_Util::createTag($token["tagname"], $token["attribs"], $data, null, XML_UTIL_REPLACE_ENTITIES, $this->_options["multilineTags"], $attIndent) . $this->_options["linebreak"]; break; @@ -154,6 +153,19 @@ break; /* + * serialize CData section + */ + case XML_BEAUTIFIER_CDATA_SECTION: + if ($token["depth"] > 0) { + $xml = str_repeat($this->_options["indent"], $token["depth"]); + } else { + $xml = ""; + } + + $xml .= '<![CDATA['.$token["data"].']]>' . $this->_options["linebreak"]; + break; + + /* * serialize entity */ case XML_BEAUTIFIER_ENTITY: http://cvs.php.net/diff.php/pear/XML_Beautifier/Beautifier/Tokenizer.php?r1=1.6&r2=1.7&ty=u Index: pear/XML_Beautifier/Beautifier/Tokenizer.php diff -u pear/XML_Beautifier/Beautifier/Tokenizer.php:1.6 pear/XML_Beautifier/Beautifier/Tokenizer.php:1.7 --- pear/XML_Beautifier/Beautifier/Tokenizer.php:1.6 Sun Feb 1 16:45:43 2004 +++ pear/XML_Beautifier/Beautifier/Tokenizer.php Sat Apr 17 05:01:29 2004 @@ -65,6 +65,13 @@ var $_mode = "xml"; /** + * indicates, whether parser is in cdata section + * @var boolean + * @access private + */ + var $_inCDataSection = false; + + /** * Tokenize a document * * @param string $document filename or XML document @@ -150,8 +157,14 @@ return true; } + if ($this->_inCDataSection === true) { + $type = XML_BEAUTIFIER_CDATA_SECTION; + } else { + $type = XML_BEAUTIFIER_CDATA; + } + $struct = array( - "type" => XML_BEAUTIFIER_CDATA, + "type" => $type, "data" => $cdata, "depth" => $this->_depth ); @@ -168,7 +181,7 @@ * @param string data * @return void */ - function piHandler($parser, $target, $data) + function piHandler($parser, $target, $data) { $struct = array( "type" => XML_BEAUTIFIER_PI, @@ -268,6 +281,18 @@ "depth" => $this->_depth ); /* + * handle start of cdata section + */ + } elseif ($data == "<![CDATA[") { + $this->_inCDataSection = true; + $struct = null; + /* + * handle end of cdata section + */ + } elseif ($data == "]]>") { + $this->_inCDataSection = false; + $struct = null; + /* * handle XML declaration */ } elseif (strncmp("<?", $data, 2) == 0) { @@ -313,7 +338,9 @@ ); } - $this->_appendToParent($struct); + if (!is_null($struct)) { + $this->_appendToParent($struct); + } return true; } @@ -367,6 +394,7 @@ $this->_depth = 0; $this->_struct = array(); $this->_mode = "xml"; + $this->_inCDataSection = false; } } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/XML_Beautifier/examples/example2.php?r1=1.3&r2=1.4&ty=u Index: pear/XML_Beautifier/examples/example2.php diff -u pear/XML_Beautifier/examples/example2.php:1.3 pear/XML_Beautifier/examples/example2.php:1.4 --- pear/XML_Beautifier/examples/example2.php:1.3 Mon Jan 12 15:10:34 2004 +++ pear/XML_Beautifier/examples/example2.php Sat Apr 17 05:01:29 2004 @@ -10,7 +10,7 @@ */ error_reporting( E_ALL ); - $xmlString = '<xml><foo bar="tomato &amp; Cheese"/><argh>foobar</argh></xml>'; + $xmlString = '<xml><foo bar="tomato &amp; Cheese"/><argh>foobar<![CDATA[ Test ]]></argh></xml>'; require_once 'XML/Beautifier.php'; $fmt = new XML_Beautifier(); http://cvs.php.net/diff.php/pear/XML_Beautifier/examples/test.xml?r1=1.2&r2=1.3&ty=u Index: pear/XML_Beautifier/examples/test.xml diff -u pear/XML_Beautifier/examples/test.xml:1.2 pear/XML_Beautifier/examples/test.xml:1.3 --- pear/XML_Beautifier/examples/test.xml:1.2 Mon Nov 10 15:51:12 2003 +++ pear/XML_Beautifier/examples/test.xml Sat Apr 17 05:01:29 2004 @@ -17,6 +17,7 @@ ?> &foo;&bar; <intro> +<test><![CDATA[This is a CData section with an &. ]]></test> <!-- This Comment has more than one line. http://cvs.php.net/diff.php/pear/XML_Beautifier/examples/test2.xml?r1=1.9&r2=1.10&ty=u Index: pear/XML_Beautifier/examples/test2.xml diff -u pear/XML_Beautifier/examples/test2.xml:1.9 pear/XML_Beautifier/examples/test2.xml:1.10 --- pear/XML_Beautifier/examples/test2.xml:1.9 Sun Feb 1 16:45:45 2004 +++ pear/XML_Beautifier/examples/test2.xml Sat Apr 17 05:01:29 2004 @@ -3,14 +3,14 @@ <!ENTITY foo SYSTEM "foo.xml"> <!ENTITY bar SYSTEM "bar.xml"> ]> -<DOCUMENT TITLE="Current News"> - <META FOO="bar" PROJECT="none"> - <KEYWORDS /> - <DESCRIPTION /> - <AUTHOR>Stephan Schmidt</AUTHOR> - <GETMETANAV /> - </META> - <PAGE LABEL="PHP Application Tools" SUBLABEL="Current News"> +<document title="Current News"> + <meta foo="bar" project="none"> + <keywords /> + <description /> + <author>Stephan Schmidt</author> + <getMetaNav /> + </meta> + <page label="PHP Application Tools" sublabel="Current News"> <?PHP for($i = 0; $i < count($_GET); $i++) { echo $_GET[$i]."<br>"; @@ -18,23 +18,26 @@ ?> &foo; &bar; - <INTRO> + <intro> + <test> + <![CDATA[ This is a CData section with an &. ]]> + </test> <!-- This Comment has more than one line. --> - <INTROTITLE>Welcome to PHP Application Tools &amp; PEAR!</INTROTITLE> - <PARA> + <introtitle>Welcome to PHP Application Tools &amp; PEAR!</introtitle> + <para> If you&apos;re new to pat, and would like <!-- This is a comment in a single line that contains an &amp; --> to know what we do here, take a look at - <LINK URL="/about/project.xml">&quot;About Pat&quot;</LINK> + <link url="/about/project.xml">&quot;About Pat&quot;</link> or check out the - <LINK URL="/about/projectsOverview.xml">&quot;projects overview&quot;</LINK> + <link url="/about/projectsOverview.xml">&quot;projects overview&quot;</link> . Otherwise, you probably know your way around the site already - <SMILEY TYPE="smile" /> - </PARA> - </INTRO> - </PAGE> -</DOCUMENT> + <smiley type="smile" /> + </para> + </intro> + </page> +</document>
« previous php.pear.cvs (#18336) next »