Jump to content

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


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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.