LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-05-2004, 08:36 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
Parsing XML tags with php, can't get attributes of a tag


Hi,

I've written a piece of code for finding out what version of RSS a stream is using:

Code:
// Gets the attributes of the rss tag
function startElement( $parser, $name, $attrs )
{
    global $currentElements, $feedCount, $classArray;

    if( $name == "rss" )
    {
	$feedCount += 1;
        if (sizeof($attrs)) 
	{
	    // Enter any attributes of rss tag into the array
            while (list($k, $v) = each($attrs)) 
	    {
		$classArray[rss_version][$k] = $v;
            }
	}
    }
}
Works fine and puts the output into an array e.g.:

$classArray[rss_version][version] = 2;

. excuse the unusual placements of the braces, it's the standard for my CMS.

The Problem

When I add some more code, which I wrote seperately and also works, I can't seem to get the two to work in union:

Code:
function startElement( $parser, $name, $itemCount )
{
    global $currentElements, $feedCount, $itemCount, $classArray;
  
    // Gets the attributes of the rss tag
    if( $name == "rss" )
    {
	$feedCount += 1;
        if (sizeof($attrs)) 
	{
	    // Enter any attributes of rss tag into the array
            while (list($k, $v) = each($attrs)) 
	    {
		$classArray[rss_version][$k] = $v;
            }
	}
	else
	{
	    echo "Unable to identify the class of object to be created\n";
	}
    }

    if ( ( $name == 'summary' ) or ( $name == 'body' ) )
    {
	push( $currentElements, $name );
    }
    else
    {
	array_push( $currentElements, $name );
    }

    if( $name == "item" )
    {
	$itemCount += 1;
    }

}
No errors, but from inserting echo's in various place I can tell that "if (sizeof($attrs))" returns false in this situation and I don't know why! Can anyone shed any light? Let me know if you need more code to help me figure it out.

Regards,

James
 
Old 05-05-2004, 10:32 AM   #2
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
Took a break and came back to it and figured it out for myself:
Code:
function startElement( $parser, $name, $itemCount )
should have been
Code:
function startElement( $parser, $name, $attrs )
Thanks for putting up with me waste your time!!

James
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT/xml enforcing full tag syntax bigearsbilly Programming 2 11-23-2005 02:38 AM
Need help to strip XML & XSL tags from multiple files dfrechet Programming 9 10-12-2005 06:52 AM
Remove XML style tags using C kuronai Programming 8 11-12-2004 12:27 AM
xml parsing with xsl crabboy Programming 2 03-22-2004 01:45 AM
regular expression for parsing html tags Bert Linux - Software 3 10-14-2002 04:31 PM


All times are GMT -5. The time now is 01:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration