function test_getText_getToken_STRLEN_FALSE() { XML_PullParser_trimCdata(false); XML_PullParser_excludeBlanks(false); $token = $this->parser->XML_PullParser_getToken(); $str_1 = $this->parser->XML_PullParser_getText($token, 0, FALSE); XML_PullParser_trimCdata(true); XML_PullParser_excludeBlanks(true); $str_2 = $this->parser->XML_PullParser_getText($token, 0, FALSE); $this->assertTrue($str_2 > $str_1); }
function tearDown() { XML_PullParser_trimCdata(false); XML_PullParser_excludeBlanks(false); $this->parser->XML_PullParser_free(); }
<?php require_once "XML_PullParser_NS_doc.inc"; XML_PullParser_excludeBlanks(true); XML_PullParser_trimCdata(true); XML_PullParser_excludeBlanksStrict(true); $doc = <<<DOC <Movies xmlns = "http://fedora.gemini.ca/local/" xmlns:mov = "http://room535.org/movies/mov/" xmlns:star = "http://room535.org/movies/star/" xmlns:title = "http://room535.org/movies/title/" xmlns:date = "http://room535.org/movies/dates/" > <Movie> <title:Title>Gone With The wind</title:Title> <date:date date:day="25" date:month="Apr">1939</date:date> <star:leading_lady>Vivien Leigh</star:leading_lady> <star:leading_man>Clark Gable</star:leading_man> </Movie> <mov:Movie> <title:Title>How Green Was My Valley</title:Title> <date:date day = "2" month="May">1941</date:date> <star:leading_lady>Maureen O'Hara</star:leading_lady> <star:leading_man>Walter Pidgeon</star:leading_man> </mov:Movie> <Movie> <title:Title>Jurassic Park</title:Title> <date:date date:day="15" date:month="June">1993</date:date>
function parse_files($file) { global $pattern, $constants_pattern; XML_PullParser_excludeBlanks(true); XML_PullParser_trimCdata(true); $tags = array("formalpara", "blockquote", "simpara"); $child_tags = array('programlisting', "title", "para", "simplelist", "member"); $parser = new XML_PullParser($file, $tags, $child_tags); XML_PullParser_excludeBlanks(true); XML_PullParser_trimCdata(true); $token = ""; while ($token = $parser->XML_PullParser_getToken()) { if ($parser->XML_PullParser_isTypeOf("formalpara", $token)) { $title = $parser->XML_PullParser_getElement('title'); $title = $parser->XML_PullParser_getText($title); if ($title) { if (preg_match_all('/XML_PullParser(_\\w+)/', $title, $matches)) { index_functions($matches[1]); } } $para = $parser->XML_PullParser_getElement('para'); if ($text = $parser->XML_PullParser_getText($para)) { if (preg_match_all($constants_pattern, $text, $matches)) { index_constants($matches[1]); } elseif (preg_match_all('/XML_PullParser(_\\w+)/', $text, $matches)) { index_functions($matches[1]); } elseif (preg_match_all($pattern, $text, $matches)) { index_terms($matches[1]); } } } elseif ($parser->XML_PullParser_isTypeOf("blockquote", $token)) { $title = $parser->XML_PullParser_getText('title'); if ($title) { if (preg_match_all('/XML_PullParser(_\\w+)/', $title, $matches)) { index_functions($matches[1]); } } } elseif ($parser->XML_PullParser_isTypeOf("simpara", $token)) { $text = $parser->XML_PullParser_getText($token); if (preg_match_all($constants_pattern, $text, $matches)) { index_constants($matches[1]); } elseif (preg_match_all('/XML_PullParser(_\\w+)/', $text, $matches)) { index_functions($matches[1]); } } } $parser->XML_PullParser_free(); }
function getBody($file) { $tags = array("formalpara", "blockquote", "simpara", "indexdiv"); $child_tags = array("classname", "ulink", "link", "indexentry"); $parser = new XML_PullParser($file, $tags, $child_tags); $token = ""; while ($token = $parser->XML_PullParser_getToken()) { if ($parser->XML_PullParser_isTypeOf("formalpara", $token)) { $td_prev = ""; $td_next = ""; $link_text = ""; if ($link = $parser->XML_PullParser_getElement('ulink')) { while ($link = $parser->XML_PullParser_nextElement()) { $link_text = $parser->XML_PullParser_getText($link); $url_array = $parser->XML_PullParser_getAttributes($link); $url = $parser->XML_PullParser_getAttrVal('url', $url_array); $type = $parser->XML_PullParser_getAttrVal('type', $url_array); if ($type == "next") { $td_next = "<TD align='right' class='navigation'><b>Next: </b>"; $td_next .= "<a href='article2html.php?fn={$url}' class='navigation'>{$link_text}</a></td>"; } if ($type == "prev") { $td_prev = "<TD align='left' class='navigation'><b>Prev: </b>"; $td_prev .= "<a href='article2html.php?fn={$url}'>{$link_text}</a></td>"; } } if ($td_prev || $td_next) { echo "<TABLE width='800'><TR>{$td_prev}" . $td_next; echo "</table> \n"; continue; } } $parser->XML_PullParser_resetCurrentElement($token); //current element has to be restored from ulink $mark_up = $parser->XML_PullParser_getCSSSpans(array("code" => "code", "emphasis" => "emphasis", "classname" => "classname", "envar" => "code", "superscript" => "super")); // $mark_up += $parser->XML_PullParser_getHTMLTags(array("classname"=>"b")); $anchor = ""; if ($parser->XML_PullParser_isChildOf('anchor', $token)) { $anchor_id = $parser->XML_PullParser_getAttributes('anchor'); $anchor_id = $parser->XML_PullParser_getAttrVal('id', $anchor_id); //echo "<A Name='$anchor_id'></a>"; $anchor = "<A Name='{$anchor_id}'>"; } if ($parser->XML_PullParser_isChildOf('simplelist', $token)) { $list = $parser->XML_PullParser_getChild('simpleList'); $attr_array_role = $parser->XML_PullParser_getAttributes('simpleList'); if ($attr_array_role) { $start_num = $parser->XML_PullParser_getAttrVal('role', $attr_array_role); } if (!$start_num) { $start_num = 1; } $which = 1; $items = ""; while ($member = $parser->XML_PullParser_getChild('member', $which, $list)) { $member_xcl = $parser->XML_PullParser_childXCL($member, 'phrase'); $member_text = $parser->XML_PullParser_getTextMarkedUp($mark_up, $member_xcl); if ($phrase = $parser->XML_PullParser_getChild('phrase', 1, $member)) { if ($phrase_text = $parser->XML_PullParser_getTextMarkedUp($mark_up, $phrase)) { $member_text .= "\n<table width=600><td class='list_phrase'>" . trim($phrase_text) . "\n</table>\n"; rewrite_HTML_Link($member_text); } } $items .= "<LI>" . trim($member_text) . "\n"; $which++; } $title = $parser->XML_PullParser_getTextMarkedUp($mark_up, 'title'); if ($title) { echo "<br>" . $title . "<br>"; } /* text in this para is assumed to be an intro to the list, which means that any text following the list would be concatenated with the text at top of list and printed at top of list */ $para = $parser->XML_PullParser_childXCL($token, 'simpleList', 'title'); //remove simplelist if ($list_intro_text = trim($parser->XML_PullParser_getTextMarkedUp($mark_up, $para))) { echo '<TABLE width="800"><TR><TD class="white_block">' . $list_intro_text . "</table>\n"; } if ($anchor) { echo "{$anchor} <OL TYPE = '1' START = '{$start_num}'> </a>"; } else { echo "<OL TYPE = '1' START = '{$start_num}'>\n"; } echo $items; echo "</OL>\n"; continue; } if ($parser->XML_PullParser_isChildOf('token', $token)) { $len = strlen($parser->XML_PullParser_getText('token')); $len *= 10; $len = round((800 - $len) / 2); if ($len < 10) { $len = 20; } $len = $len . "px"; $mark_up += $parser->XML_PullParser_getStyledTags(array("token" => "h4"), array("style" => "left:{$len}")); } echo '<p><div class="para">'; if ($anchor) { echo $anchor . "</a>"; } if ($parser->XML_PullParser_isChildOf('title', $token)) { $title = $parser->XML_PullParser_getTextMarkedUp($mark_up, 'title'); if ($title) { echo "<br>" . $title . "<br>"; } } if ($parser->XML_PullParser_isChildOf('para', $token)) { $text = $parser->XML_PullParser_getTextMarkedUp($mark_up, "para"); rewrite_HTML_Link($text); /* if(preg_match('/href\s*=\s*".*?\.xml/',$text)) { if($text = preg_replace('/href\s*="(.*?)xml/','href="article2html.php?fn=\\1xml',$text)) { echo "\n<!-- REPLACEMENT MADE -->\n"; } } */ $text = preg_replace('/<\\s/', '<', $text); $text = preg_replace('/\\s>/', '>', $text); echo $text; } echo "</p></div>\n\n"; } elseif ($parser->XML_PullParser_isTypeOf("blockquote", $token)) { if ($parser->XML_PullParser_isChildOf('anchor', $token)) { $anchor_id = $parser->XML_PullParser_getAttributes('anchor'); $anchor_id = $parser->XML_PullParser_getAttrVal('id', $anchor_id); echo "<A Name='{$anchor_id}'>"; } if ($attr = $parser->XML_PullParser_getAttributes("blockquote")) { $role = $parser->XML_PullParser_getAttrVal('role', $attr); if ($role == 'box' || $role == 'blank_box') { $bgcolor = '#eeeeee'; $class = 'block'; if ($role == 'blank_box') { $bgcolor = '#ffffff'; $class = 'white_block'; } $mark_up = $parser->XML_PullParser_getCSSSpans(array("code" => "code", "emphasis" => "emphasis", "classname" => "classname")); // $mark_up += $parser->XML_PullParser_getHTMLTags(array("classname"=>"b")); $title = $parser->XML_PullParser_getText("title"); $list = $parser->XML_PullParser_getChild('simpleList'); $which = 1; $items = ""; while ($member = $parser->XML_PullParser_getChild('member', $which, $list)) { $member_text = $parser->XML_PullParser_getTextMarkedUp($mark_up, $member); rewrite_HTML_Link($member_text); $items .= "<tr><td class='{$class}'>" . trim($member_text) . "</td>\n"; $which++; } echo "<table border=1 bgcolor='" . $bgcolor . "' width = 750 cellpadding ='6'>\n" . "<tr><th align='left' class='{$class}'>{$title}" . $items . "</table>\n"; continue; } } $tab_x_2 = ' '; $code = false; echo '<p><div class="block">'; if ($anchor = $parser->XML_PullParser_getChild("anchor")) { $anchor_id = $parser->XML_PullParser_getAttributes($anchor); echo '<A Name="' . $parser->XML_PullParser_getAttrVal('id', $anchor_id) . '"></A>'; } $title = $parser->XML_PullParser_getText("title"); if ($attr = $parser->XML_PullParser_getAttributes("title")) { $role = $parser->XML_PullParser_getAttrVal('role', $attr); if ($role && preg_match('/^code$/i', $role)) { $title = '<span class="code_title" style="font-style:italic;">' . $title . "</span>"; $code = true; } } $text = $parser->XML_PullParser_getText("programlisting"); $text = preg_replace('/<\\s/', '<', $text); $text = preg_replace('/\\s>/', '>', $text); if (!$code) { $text = preg_replace('/^[\\t ]+/ms', "", $text); // remove leading spaces } // replace dummy lines of single dot with bullets $text = preg_replace('/^\\.\\s*$/ms', "{$tab_x_2}•", $text); print "<center><b>{$title}</b></center>\n"; print "<pre>{$text}</pre></div>\n"; } elseif ($parser->XML_PullParser_isTypeOf("indexdiv", $token)) { XML_PullParser_excludeBlanks(true); XML_PullParser_trimCdata(true); $title = $parser->XML_PullParser_getText('title'); echo "\n<P><b>{$title}</b>\n"; $entries = $parser->XML_PullParser_getElement('indexentry'); $seq = $parser->XML_PullParser_getSequence(); $close_prevList = ""; foreach ($seq as $index_entry) { list($index_tag, $index_val) = each($index_entry); if ($text = $parser->XML_PullParser_getText($index_tag, $index_val)) { if ($url_array = $parser->XML_PullParser_getAttributes("ULINK", $index_val)) { $url = $parser->XML_PullParser_getAttrVal('url', $url_array); } if (preg_match('/\\w/', $text)) { write_index_element($index_tag, $text, $close_prevList, $url); if (!$close_prevList) { $close_prevList = "</DL>\n"; } } } } echo $close_prevList; } if ($parser->XML_PullParser_isTypeOf("simpara", $token)) { if ($attr = $parser->XML_PullParser_getAttributes("simpara", 1)) { $role = $parser->XML_PullParser_getAttrVal('role', $attr); if ($role == "hr") { echo "<hr width='800' align='left'>\n"; } continue; // this will also skip over the xml contents page which has role ="contents" } $text = $parser->XML_PullParser_getText(); $mark_up = $parser->XML_PullParser_getCSSSpans(array("code" => "code", "emphasis" => "emphasis", "classname" => "classname")); // $mark_up += $parser->XML_PullParser_getHTMLTags(array("classname"=>"b")); $text = $parser->XML_PullParser_getTextMarkedUp($mark_up); echo "<table width='750' bgcolor='#eeeeee'><td class='block'><pre>{$text}</pre></table>"; } } $parser->XML_PullParser_free(); }