Jump to content

Notice: Undefined index: title in C:\xampp\htdocs\sax\links.php on line 14


attaboy

Recommended Posts

This is my XML:

 

 

<?xml version="1.0" encoding="utf-8"?>

<links>

<category desc="XAML Related">

<link url="http://longhorn.msdn.microsoft.com" desc="Longhorn SDK home" title="Source of Longhorn" />

<link url="http://longhornblogs.com" desc="Longhorn Blogs" />

<link url="http://xamlblogs.com" desc="XAML Blogs" />

<link url="http://www.xamlong.com" desc="Xamlong.com" />

<link url="http://www.mobiform.com" desc="Mobiform" />

<link url="http://www.zaml.com" desc="Zaml.com" />

<link url="http://www.zaml.net" desc="Xaml.net" />

</category>

 

<category desc="XAML Related">

<link url="http://jimslounge.com" desc="Jim's Lounge" title="Source of fun" />

<link url="http://longhorn.com" desc="Longhorn Cheese" />

. . .

</xml>

 

This is my php:

 

 

<?php
function startElemHandler($parser, $name, $attribs) {
if (strcasecmp($name, "links") == 0) {
echo "<div id='linklist'>\n";
}
if (strcasecmp($name, "category") == 0) {
$desc = $attribs['desc'];
echo "<p>$desc</p><ul>\n";
}
if (strcasecmp($name, "link") == 0) {
$url = $attribs['url'];
$desc = $attribs['desc'];
[b]$title = $attribs['title'];[/b]

echo "<li><a href='$url' target='_blank'";
if ($title != " ")
echo " title='$title'";
echo ">";

if ($desc == " ")
echo "$url";
else
echo "$desc";
echo "</a></li>";
}
}

function endElemHandler($parser, $name) {
if (strcasecmp($name, "links") == 0) {
echo "</div>\n";
}
if (strcasecmp($name, "category") == 0) {
echo "</ul>\n";
}
}

$parser = xml_parser_create();
xml_set_element_handler($parser, 'startElemHandler', 'endElemHandler');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

$strXML = implode("",file("links.xml"));

xml_parse($parser, $strXML);

xml_parser_free($parser);
?>

 

I've created variables to hold values of all the attributes. $url, and $desc don't generate a warning

why does $title?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.