Php XML Parsing
Posted: Tue Jan 10, 2006 5:37 pm
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.
Here's the on that works...
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;
}
}
}
}