예제 #1
0
<?php

require_once "XML_PullParser.inc";
$tags = array('para');
$child_tags = array();
$parser = new XML_PullParser("List.xml", $tags, $child_tags);
$parser->XML_PullParser_getToken();
$list = $parser->XML_PullParser_getChild('simpleList');
$which = 1;
$items = "";
echo " < OL>\n";
while ($member = $parser->XML_PullParser_getChild('member', $which, $list)) {
    $member_text = $parser->XML_PullParser_getText($member);
    $items .= " < LI>" . trim($member_text) . "\n";
    $which++;
}
echo $items;
echo " < /OL>\n";
/*  Result: Child token $member returned by XML_PullParser_getChild
    [8] => S__MEMBER
    [9] => Array
        (
        )

    [10] => Array
        (
            [cdata] =>
        array XML_PullParser_getChild (string $child, [integer $which = 1], [array $el = ""])

        )
예제 #2
0
<?php

require_once "XML_PullParser.inc";
XML_PullParser_excludeBlanks(true);
XML_PullParser_trimCdata(true);
$tags = array("DNS");
$child_tags = array("Entry");
$parser = new XML_PullParser("DNS.xml", $tags, $child_tags);
while ($token = $parser->XML_PullParser_getToken()) {
    $entry = $parser->XML_PullParser_getElement("entry");
    $child = $parser->XML_PullParser_getChild("server", 2, $entry);
    $child = $parser->XML_PullParser_getText("server", 2, $entry);
    echo "{$child}\n";
    $attr_array = $parser->XML_PullParser_getAttributes("server", 2, $child);
    if ($attr_array) {
        foreach ($attr_array as $n => $v) {
            echo "{$n} -- {$v}\n";
        }
    } elseif ($attr_array === FALSE) {
        $err = XML_PullParser_Errors_userDefined("Bad Attributes array");
        echo XML_PullParser_Errors_getUserDefined($err) . "\n";
        echo XML_PullParser_Errors_Trace() . "\n";
        exit;
    }
}
/* Result
example_2.com
User defined error: Bad Attributes array
Line: 26, Top Level

------Error Trace------------
예제 #3
0
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>&nbsp;&nbsp;&nbsp;\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/', '&lt;', $text);
                $text = preg_replace('/\\s>/', '&gt;', $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 = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            $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/', '&lt;', $text);
            $text = preg_replace('/\\s>/', '&gt;', $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}&bull;", $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();
}