473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_key ="#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($parser, $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($current_tag, '#');
$current_tag = substr($current_tag, 0, $tag_key);
}

function contents($parser, $data){ //A function to handle the data between the tags
global $current_tag, $link_key, $title_key, $description_key, $counter, $story_array, $description_value; //$gen_key,
$description_value=strip_tags($description_key);
switch($current_tag){
case $title_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->title = $data;
//$counter++;
break;
case $description_value:
$story_array[$counter]->description = $data;
$counter++;
break;


}
}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startTag", "endTag");

xml_set_character_data_handler($xml_parser, "contents");

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

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

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

xml_parser_free($xml_parser);

fclose($fp);

?>
<html>
<head>
<title>XML Parsint Headline News</title>
</head>
<body bgcolor="#FFFFFF">
<script language="PHP">
echo('Today is <b>'.date('l F jS').'</b>');
for($x=0;$x<count($story_array);$x++){
echo('<BR>title :' .$story_array[$x]->title);
echo ('<BR>description :' .$story_array[$x]->description);
}
</script>
</body>
</html>
Mar 24 '07 #1
1 2361
ronverdonk
4,258 Expert 4TB
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
Mar 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: Mitchua | last post by:
I am trying to use HTML::Parser to parse an HTML file, remove all HTML tags (including comments, etc.), replace all ENTITIES (e.g. &amp), and put the result into a variable as a string. I figure...
21
by: Boris Ammerlaan | last post by:
This notice is posted about every week. I'll endeavor to use the same subject line so that those of you who have seen it can kill-file the subject; additionally, Supersedes: headers are used to...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
6
by: mumrah | last post by:
When getting different elements out of an array in JS, i know array.item(0) and array both return the 0th element. My question, will this work in any instance?
8
by: Lachlan Hunt | last post by:
Hi, I'm interested in finding out how erroneous comment syntax within an HTML document should be handled by a parser, according to SGML rules. At present, every browser handles comments in...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
2
by: Felipe De Bene | last post by:
I'm having problems parsing an HTML file with the following syntax : <TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'> <TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH> <TH...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.