remove html syntax in xml parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prakash280681
    New Member
    • Mar 2007
    • 1

    remove html syntax in xml parsing

    how to get the correct result when we parse the xml code.Because in parsing when it get the syntax like < and & it break it and forward..

    i use the code----


    <?php

    $xml_file = "news.xml";

    $title_key ="#CHANNEL#ITEM #TITLE"; //XML tag keys
    $description_ke y ="#CHANNEL#ITEM #DESCRIPTION";

    $story_array = array(); //An array to store information

    $counter = 0; //A counter
    class xml_story{ //A class
    var $links, $title, $description;
    }

    function startTag($parse r, $data){ //A function to handle the start tags
    global $current_tag;
    $current_tag .= "#$data";
    }

    function endTag($parser, $data){ //A function to handle the end tags
    global $current_tag;
    $tag_key = strrpos($curren t_tag, '#');
    $current_tag = substr($current _tag, 0, $tag_key);
    }

    function contents($parse r, $data){ //A function to handle the data between the tags
    global $current_tag, $link_key, $title_key, $description_ke y, $counter, $story_array, $description_va lue; //$gen_key,
    $description_va lue=strip_tags( $description_ke y);
    switch($current _tag){
    case $title_key:
    $story_array[$counter] = new xml_story();
    $story_array[$counter]->title = $data;
    //$counter++;
    break;
    case $description_va lue:
    $story_array[$counter]->description = $data;
    $counter++;
    break;


    }
    }

    $xml_parser = xml_parser_crea te();

    xml_set_element _handler($xml_p arser, "startTag", "endTag");

    xml_set_charact er_data_handler ($xml_parser, "contents") ;

    $fp = fopen($xml_file , "r") or die("Could not open file");

    $data = fread($fp, filesize($xml_f ile)) or die("Could not read file");

    if(!(xml_parse( $xml_parser, $data, feof($fp)))){
    die("Error on line " . xml_get_current _line_number($x ml_parser));
    }

    xml_parser_free ($xml_parser);

    fclose($fp);

    ?>
    <html>
    <head>
    <title>XML Parsint Headline News</title>
    </head>
    <body bgcolor="#FFFFF F">
    <script language="PHP">
    echo('Today is <b>'.date('l F jS').'</b>');
    for($x=0;$x<cou nt($story_array );$x++){
    echo('<BR>title :' .$story_array[$x]->title);
    echo ('<BR>descripti on :' .$story_array[$x]->description) ;
    }
    </script>
    </body>
    </html>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to TSDN.

    Before you continue, please read the Posting Guidelines before you post in this forum!.

    Especially the part about enclosing shown code within code or php tags! The code shown is unreadable.

    moderator

    Comment

    Working...