Stopping an XML parser

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jul 10, 2003 5:46 am

Stopping an XML parser

Postby wmdigital » Thu Jul 10, 2003 5:53 am

Hi everyone. I am trying to figure out the best way to stop an XML/RSS parser once I have gotten three or so tags and don't need any more. I am certain that this involves the function that handles the endElement of an item.

I can't throw in an exit() or die() since the page had other PHP stuff going on further down the page.

Also, I am creating the parser class from scratch so there's nothing that I can't change or aurment.

Any ideas?

william m-

User avatar
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Thu Jul 10, 2003 6:23 am

As a general tip, reinventing the wheel is usually a bad idea. There are probably a dozen PHP XML parsers out there, so I can't fathom why you'd write your own.

Anyway, the answer to your question depends largely on how you're implementing the parser. But if it's running in any sort of loop, and I can't imagine how else you'd do it, you can use the break command to exit the current loop and continue on with the rest of the script.

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jul 10, 2003 5:46 am

Postby wmdigital » Thu Jul 10, 2003 6:50 am

My reason for creating the parser from scratch is in part to see if I can do it and in part because the people who are feeding me the XML/RSS have something line the following:

<TITLE>Title here</TITLE>
<LINK>Link here</LINK>
<event:timeStart>Time here</event:timeStart>
<event:timeEnd>Time here</event:timeEnd>

Since I am unsure as to handle the tags like 'event:timeStart' and haven't seen any parser that had any XML structured like that going into it. I am treating it as a string name for now.

The parser is being defined in the head and called in the body where it is needed. There are other scripts that will be called after this so I need it to just stop after only executing three endElement functions. Breaking will stop that one function but I am at a loss for stopping the larger parser function. Maybe setting a boolean?

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests