473,387 Members | 1,529 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,387 software developers and data experts.

Parse embedded html tags within XML file?

I am trying to write a general function XML file parser, but it keeps
choking when it finds embedded HTML within the text, for example:

<item>
<title>New PHP eBooks in PDF</title>
<description>
<p style="color: red">This entry was brought to you by <a
href="http://tutorials.lockergnome.com/">Lockergnome's
Tutorials</a></p><strong>New PDFs are Available!</strong>...
</description>

When I try to read this all I get is "p style=" (no quotes). Is there a
function or routine I can use to read this as text so that it can be
printed out in HTML?

Thanks,

Miki
Jul 17 '05 #1
3 3159
Hi
I am trying to write a general function XML file parser, but it keeps
choking when it finds embedded HTML within the text, for example:

<item>
<title>New PHP eBooks in PDF</title>
<description>
<p style="color: red">This entry was brought to you by <a
href="http://tutorials.lockergnome.com/">Lockergnome's
Tutorials</a></p><strong>New PDFs are Available!</strong>...
</description>

When I try to read this all I get is "p style=" (no quotes). Is there a
function or routine I can use to read this as text so that it can be
printed out in HTML?


you may try to treat anything beetween description tags with htmlentities()
a then revert it with html_entity_decode().

--
hope it helps
Barbara
Jul 17 '05 #2
Barbara "bev" T. wrote:
Hi
I am trying to write a general function XML file parser, but it keeps
choking when it finds embedded HTML within the text, for example:

<item>
<title>New PHP eBooks in PDF</title>
<description>
<p style="color: red">This entry was brought to you by
<a href="http://tutorials.lockergnome.com/">Lockergnome's
Tutorials</a></p><strong>New PDFs are Available!</strong>...
</description>

When I try to read this all I get is "p style=" (no quotes). Is there
a function or routine I can use to read this as text so that it can
be printed out in HTML?

you may try to treat anything beetween description tags with htmlentities()
a then revert it with html_entity_decode().

I tried that but I can't seem to insert the conversion function into the
the xml parser read at the proper time. For example this code:

if (!xml_parse($xml_parser, htmlentities($data), feof($source)))
{
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}

produces the following error:
"XML error: not well-formed (invalid token) at line"

inserting the function later does nothing??

miki
Jul 17 '05 #3
> I tried that but I can't seem to insert the conversion function into the
the xml parser read at the proper time. For example this code:

if (!xml_parse($xml_parser, htmlentities($data), feof($source)))
{
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}


well that's not good.
assuming you don't know the tags that may occur in description part, you
should be able to determine the xml tags that'll be there, so
here's what I did (worked for me):

function startElement($parser, $name, $attrs) {
if (in_array($tag_name,$tags_array)){
//do something
} else return false;
}

where tags_array could be: array('ITEMS','ITEM','TITLE','DESCRIPTION')

if you don't know the xml tags... we'll have a problem unless someone else
helps you :)

--
Regards
Barbara
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred...
3
by: Mitchua | last post by:
When I run the well quoted line: my $ascii = HTML::FormatText->new->format(HTML::Parse::parse_html($html)); to remove HTML tags from an html document, it replaces all tables with "". Is there a...
2
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
8
by: Francesco Moi | last post by:
Hi. I must parse this XML document: -------------- <doc> <item> <name>Jerry</name> <message>Hi<br>My name is Jerry</message> </item> </doc>
23
by: Charles Law | last post by:
Does anyone have a regex pattern to parse HTML from a stream? I have a well structured file, where each line is of the form <sometag someattribute='attr'>text</sometag> for example <SPAN...
1
by: Patrick | last post by:
I need to parse and HTML document of the following format. I am interested to obtain all the HTML from and including the first <div class="data"> up to and including Data updated dd/mm/yyyy...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
4
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
4
by: bovanshi | last post by:
got this annoying error I'm completly new to php... and i have no clue what is wrong here, from what i can tell there is nothing rong with this code... but that isn't what the borwser say :P ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.