[thelist] PHP & XML

Nicole P nparrot at pair.com
Sun Jun 9 19:50:01 CDT 2002


The example I have uses global variables.
In StartElement, you study what element you have and set global flags.
In CharacterHandler, you handle according to your global flags, and in
EndElement, you reset your flags.
 For example, StartElement would have:
 if ($name == "CHANNEL" )
 {
  $in_channel_tag = 1;
 }


Not totally elegant, but that's the way I've been handling it for now

Nicole

----- Original Message -----
From: "Burhan Khalid" <burhankhalid at members.evolt.org>
> I'm trying to read a XML file in PHP. Things are going good, I
> can read the file (and display it, using the example from php.net)...but
> that's all I can do. I need to figure out how to get a certain element's
> data. For example, if the tag is TITLE, I need to store the data
> somewhere. How do I access this information? How do I get the
> startElement function to call the characterData function for a certain
> tag type? Is this even possible?
>
> Thanks,
> Burhan
>
> Here is the code :
>
> [ snip ]
> function startElement($parser, $name, $attribs) {
> print "&lt;<font color=\"#0000cc\">$name</font>";
>     if (sizeof($attribs)) {
>         while (list($k, $v) = each($attribs)) {
>             print " <font color=\"#009900\">$k</font>=\"<font
>                    color=\"#990000\">$v</font>\"";
>         }
>     }
>     print "&gt;";
> }
>
> function endElement($parser, $name) {
>     print "&lt;/<font color=\"#0000cc\">$name</font>&gt;";
> }
>
> function characterData($parser, $data) {
>     print "<b>$data</b>";
> }
> [ snip ]
>
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>




More information about the thelist mailing list