SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow XML error: Invalid character at line 26

    it say xml errors: Invalid character at line 26


    <?php

    class xItem {
    var $xTitle;
    var $xLink;
    var $xDescription;
    }

    // general vars
    $sTitle = "";
    $sLink = "";
    $sDescription = "";
    $arItems = array();
    $itemCount = 0;

    // ********* Start User-Defined Vars ************
    // rss url goes here
    $uFile = "http://www.wirelessdevnet.com/wirelessnews/rss/dailynews.rss";
    // descriptions (true or false) goes here
    $bDesc = true;
    // font goes here
    $uFont = "Verdana, Arial, Helvetica, sans-serif";
    $uFontSize = "2";
    // ********* End User-Defined Vars **************

    function startElement($parser, $name, $attrs) {
    global $curTag;

    $curTag .= "^$name";

    }

    function endElement($parser, $name) {
    global $curTag;

    $caret_pos = strrpos($curTag,'^');

    $curTag = substr($curTag,0,$caret_pos);

    }

    function characterData($parser, $data) { global $curTag; // get the Channel information first
    global $sTitle, $sLink, $sDescription;
    $titleKey = "^RSS^CHANNEL^TITLE";
    $linkKey = "^RSS^CHANNEL^LINK";
    $descKey = "^RSS^CHANNEL^DESCRIPTION";
    if ($curTag == $titleKey) {
    $sTitle = $data;
    }
    elseif ($curTag == $linkKey) {
    $sLink = $data;
    }
    elseif ($curTag == $descKey) {
    $sDescription = $data;
    }

    // now get the items
    global $arItems, $itemCount;
    $itemTitleKey = "^RSS^CHANNEL^ITEM^TITLE";
    $itemLinkKey = "^RSS^CHANNEL^ITEM^LINK";
    $itemDescKey = "^RSS^CHANNEL^ITEM^DESCRIPTION";

    if ($curTag == $itemTitleKey) {
    // make new xItem
    $arItems[$itemCount] = new xItem();

    // set new item object's properties
    $arItems[$itemCount]->xTitle = $data;
    }
    elseif ($curTag == $itemLinkKey) {
    $arItems[$itemCount]->xLink = $data;
    }
    elseif ($curTag == $itemDescKey) {
    $arItems[$itemCount]->xDescription = $data;
    // increment item counter
    $itemCount++;
    }
    }

    // main loop
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    if (!($fp = fopen($uFile,"r"))) {
    die ("could not open RSS for input");
    }
    while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
    die(sprintf("XML error: &#37;s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
    }
    }
    xml_parser_free($xml_parser);


    // write out the items
    ?>
    <html>
    <head>
    <title><?php echo ($sTitle); ?></title>
    <meta name = "description" content = "<?php echo ($sDescription); ?>">
    </head>
    <body bgcolor = "#FFFFFF">
    <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($sLink); ?>"><?php echo($sTitle); ?></a></font>
    <br>
    <br>
    <?php
    for ($i=0;$i<count($arItems);$i++) {
    $txItem = $arItems[$i];
    ?>
    <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font>
    <br>
    <?php
    if ($bDesc) {
    ?>
    <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?>
    <br>
    <?php
    }
    echo ("<br>");
    }
    ?>
    </body>
    </html>
    what do you think is the problem?

    thanks in advance.

  2. #2
    SitePoint Member etheon's Avatar
    Join Date
    Aug 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The XML parser you're using is unable to parse the file since its not valid XML. The error is within the XML file and not the code per se.

  3. #3
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by etheon View Post
    The XML parser you're using is unable to parse the file since its not valid XML. The error is within the XML file and not the code per se.
    Precisely. We will need to see the XML file. It is probably a case of having a HTML non-entity character such as < or >.
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •