473,660 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.locke rgnome.com/">Lockergno me'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 3180
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.locke rgnome.com/">Lockergno me'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_dec ode().

--
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.locke rgnome.com/">Lockergno me'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_dec ode().

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($xm l_parser, htmlentities($d ata), feof($source)))
{
die(sprintf("XM L error: %s at line %d",
xml_error_strin g(xml_get_error _code($xml_pars er)),
xml_get_current _line_number($x ml_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($xm l_parser, htmlentities($d ata), feof($source)))
{
die(sprintf("XM L error: %s at line %d",
xml_error_strin g(xml_get_error _code($xml_pars er)),
xml_get_current _line_number($x ml_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($p arser, $name, $attrs) {
if (in_array($tag_ name,$tags_arra y)){
//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
3552
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 to me. I recently created a BBS (Bulletin Board Service) on my website where I allow people to post messages via a form. It just occurred to me that conceivably they could embed php code in their message trying to 'hack' my site. So I
3
3499
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 quick and easy way to get the table content parsed too? Thanks a lot, Mitchua
2
2847
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 any html from the xml file as text, ie its displaying as text <br/> and <b> etc
8
3751
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
2569
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 CLASS='myclass'>A bit of text</SPAN>, or Just some text, without tags
1
2260
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 (where dd/mm/yyyy will change). what kind of regular expressions can I use? Note I want everything in the core of the HTML including all the tags within the div tags. <html> <head>
13
4176
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 from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
4
3029
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 find styles embedded within the tags eg: <h3 id="pageName">Have a great day!! </h3> This throws an error, whereas <h3 >Thank you for your purchase! </h3works like a charm. It also falls over when crappy code has <h3>&nbsp;</h3between the tags.
4
11620
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 Parse error: parse error, unexpected T_VARIABLE in main.php on line 15 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title></title>
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.