6 replies [Last post]
thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 15 weeks 15 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

Simple question. I'm using an XML file and parsing it through PHP to my news page. I want to be able to update the news.xml file (which I can) and it updates the html (which it does).

However, before I used php, I used the <acronym > tag in the html. How can I reproduce this in the XML text?

I tried just using <acronym >, which wrote that out. Then I tried escaping the tags with \, but that didn't display the acronym tags, just the acronym itself.

I'm new to this, so any ideas?

Verschwindende wrote:
  • CSS doesn't make pies

Tags:
briski
briski's picture
Offline
Elder
London
Last seen: 8 years 3 weeks ago
London
Timezone: GMT+1
Joined: 2004-02-16
Posts: 1066
Points: 0

HTML tags in XML

you want <acronym> to appear on screen as readable text?

Does using &lt;acronym&gt; not work?

It's of course possible that I have totally missunderstood mind Wink

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 15 weeks 15 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

HTML tags in XML

No, I want the acronym tag to function on the page. If I wanted it readable (ie, explaining the code), I would use < and >. I want it to actually produce the acronym. (If that makes sense).

Verschwindende wrote:
  • CSS doesn't make pies

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 22 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

HTML tags in XML

When you say XML, do you specifically mean an RSS feed?

If you are using an RSS feed, just put whatever HTML you want in the description, and make sure the PHP is parsing it properly - or basically just dumping it out. It should then just write the <acronym> tags to the HTML fine.

It'd be clearer if you've got an example somewhere...

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 15 weeks 15 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

HTML tags in XML

The page it generates can be found at

http://www.pleth0ra.co.uk/ukcoders/index.php

The XML news feed is at

http://www.pleth0ra.co.uk/ukcoders/news.xml

Any help would be appreciated.

Verschwindende wrote:
  • CSS doesn't make pies

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 22 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

HTML tags in XML

I *think* it's to do with your php xml-parsing thing. The XML looks good (except Firefox found the 'commented-out' </channel> at the end, guess those comments don't work!). The XML-parser seems to be trying to do something with those tags, rather than ignore them since they're in the "description" tags.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 15 weeks 15 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

HTML tags in XML

There's something else I want. I know in an RSS feed, your supposed to have your channel and a description of it, then the news items - so other sites can display your news.

However, I don't want to display the channel or description on my site.

Is there a way I can do it?

Also, am I parsing it to the html right? 'm new to this. The code I use is as follows:

<div id="content">
  <?php
	include ('news.php');
  ?>
</div>

to include the news file, then in news.php:

<?php

  // Global variables for function use.


  $GLOBALS['title'] = false;

  $GLOBALS['link']  = false;

  $GLOBALS['description'] = false;

  $GLOBALS['author'] = false;

  $GLOBALS['titletext'] = null;

  $GLOBALS['linktext'] = null;

  $GLOBALS['desctext'] = null;

  $GLOBALS['authtext'] = null;

 

  // function: startElement

  // Deals with the starting element

  function startElement( $parser, $tagName, $attrs ) {

    // By setting global variable of tag name

    // I can determine which tag I am currently

    // parsing.

    switch( $tagName ) {

      case 'TITLE':

        $GLOBALS['title'] = true;

        break;

      case 'LINK':

        $GLOBALS['link'] = true;

        break;

      case 'DESCRIPTION':

        $GLOBALS['description'] = true;

        break;

      case 'AUTHOR':

        $GLOBALS['author'] = true;

        break;
    }

  }

 

  // function: endElement

  // Deals with the ending element

  function endElement( $parser, $tagName ) {

    // By noticing the closing tag,

    // I can print out the data that I want.

    switch( $tagName ) {

      case 'TITLE':

        echo " <div class=\"data\"><h2>" . $GLOBALS['titletext'] . "</h2>";

        $GLOBALS['title'] = false;

        $GLOBALS['titletext'] = "";

        break;


      case 'DESCRIPTION':

        echo "<p class=\"corner\"></p>" . $GLOBALS['desctext'] . "<br/>";

        $GLOBALS['description'] = false;

        $GLOBALS['desctext'] = "";

        break;

      case 'LINK':

        echo "<a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['linktext'] . "</a><br/>";

        $GLOBALS['link'] = false;

        $GLOBALS['linktext'] = "";

        break;

      case 'AUTHOR':

        echo "<p class=\"alignright\"> - " . $GLOBALS['authtext'] . "</p><span class=\"corner\"></span> </div>";

        $GLOBALS['author'] = false;

        $GLOBALS['authtext'] = "";

        break;

    }

  

  }

 

  // function: charElement

  // Deals with the character elements (text)

  function charElement( $parser, $text ) {

    // Verify the tag that text belongs to.

    // I set the global tag name to true

    // when I am in that tag.

    if( $GLOBALS['title'] == true ) {

        $GLOBALS['titletext'] .= htmlspecialchars( trim($text) );

    } else if( $GLOBALS['link'] == true ) {

        $GLOBALS['linktext']  .= trim( $text );

    } else if( $GLOBALS['description'] == true ) {

        $GLOBALS['desctext'] .= htmlspecialchars( trim( $text ) );

    } else if( $GLOBALS['author'] == true ) {
	
	$GLOBALS['authtext'] .= htmlspecialchars( trim( $text ) );
    }

  }

  // Create an xml parser

  $xmlParser = xml_parser_create();


  // Set up element handler

  xml_set_element_handler( $xmlParser, "startElement", "endElement" );

  // Set up character handler

  xml_set_character_data_handler( $xmlParser, "charElement" );

 
  // Open connection to RSS XML file for parsing.

  $fp = fopen( "news.xml", "r" )

    or die( "Cannot read RSS data file." );

  // Parse XML data from RSS file.

  while( $data = fread( $fp, 4096 ) ) {

    xml_parse( $xmlParser, $data, feof( $fp ) );

  }

  // Close file open handler

  fclose( $fp );

  // Free xml parser from memory

  xml_parser_free( $xmlParser );

?>

I can change news.xml to another site's RSS feed and it works - except EVERYTHING is nested. I think this is to do with the parsing.

Verschwindende wrote:
  • CSS doesn't make pies