Php XML Parsing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lemonfreshmedia
Forum Commoner
Posts: 26
Joined: Fri Dec 02, 2005 7:14 pm

Php XML Parsing

Post by lemonfreshmedia »

Does any one know how I can slip a variable into this code for 'tagName'? I'm hoping to have a variable set outside the calss, is this possible?
Trying to set something up so that i can generate multiple rounds of sports drafts.

Notice I've tried 'test' to no avail.
Any help would be much appreciated,
Thanks in advance for any help.
Here's the code i tried Notice 'test' variable.

Code: Select all

<?php

class RSSParserCOL1 {
var $test = "ROUND3";
  /* The number of items to retrieve */
  var $maxitems = 500;
  
  var $insideitem = false;
  var $tag = "";
  var $title = "";
  var $description = "";
  var $link = "";
  
  var $none = "nolink";
  var $mycounter = "fakdjhfjkadhjklas";

function startElement($parser, $tagName, $attrs) {
  if ($this->insideitem) {
    $this->tag = $tagName;
  } elseif ($tagName == "ROUND3") {
    $this->insideitem = true;
  }
}

function endElement($parser, $tagName) {
  if ($tagName == $test) {
    printf("<div id=\"pick-odd\">	
	<div id=\"logo\">");
    printf("<img src=\"NHL_50/%s\"></div><div id=\"pick-details\"> ",($this->draftedby));
	printf("<strong>Draft#:%s</strong><br>",($this->draftnumber));
	
	printf("Player:%s<br>",($this->player));
	printf("Position:%s<br>",($this->position));
	printf("Drafted From:%s<br></div>
    </div>",($this->draftedfrom));

	$this->draftedfrom = "";
	$this->draftnumber = "";
    $this->position = "";
    $this->draftedby = "";
    $this->player = "";
    $this->insideitem = false;
  }
}



function characterData($parser, $data) {
  if ($this->insideitem) {
    switch ($this->tag) {
      case "DRAFTNUMBER":
        $this->draftnumber .= $data;
        break;
      case "POSITION":
        $this->position .= $data;
        break;
		case "DRAFTEDFROM":
        $this->draftedfrom .= $data;
        break;
      case "DRAFTEDBY":
        $this->draftedby .= $data;
        break;
      case "PLAYER":
        $this->player .= $data;
        break;
    }
  }
}
}

Here's the on that works...

Code: Select all

<?php

class RSSParserCOL1 {

  /* The number of items to retrieve */
  var $maxitems = 500;
  
  var $insideitem = false;
  var $tag = "";
  var $title = "";
  var $description = "";
  var $link = "";
  
  var $none = "nolink";
  var $mycounter = "fakdjhfjkadhjklas";

function startElement($parser, $tagName, $attrs) {
  if ($this->insideitem) {
    $this->tag = $tagName;
  } elseif ($tagName == "ROUND3") {
    $this->insideitem = true;
  }
}

function endElement($parser, $tagName) {
  if ($tagName == "ROUND3") {
    printf("<div id=\"pick-odd\">	
	<div id=\"logo\">");
    printf("<img src=\"NHL_50/%s\"></div><div id=\"pick-details\"> ",($this->draftedby));
	printf("<strong>Draft#:%s</strong><br>",($this->draftnumber));
	
	printf("Player:%s<br>",($this->player));
	printf("Position:%s<br>",($this->position));
	printf("Drafted From:%s<br></div>
    </div>",($this->draftedfrom));

	$this->draftedfrom = "";
	$this->draftnumber = "";
    $this->position = "";
    $this->draftedby = "";
    $this->player = "";
    $this->insideitem = false;
  }
}



function characterData($parser, $data) {
  if ($this->insideitem) {
    switch ($this->tag) {
      case "DRAFTNUMBER":
        $this->draftnumber .= $data;
        break;
      case "POSITION":
        $this->position .= $data;
        break;
		case "DRAFTEDFROM":
        $this->draftedfrom .= $data;
        break;
      case "DRAFTEDBY":
        $this->draftedby .= $data;
        break;
      case "PLAYER":
        $this->player .= $data;
        break;
    }
  }
}
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$test has to be referenced as self::$test or $this->test depending on how you are calling the functions.
Post Reply