Jump to content

$parser help needed to process XML file data


Goshawk

Recommended Posts

Hi all,

 

I am new to programming and PHP, but I am currently writing a module for Zencart, where in a sidebox visitors can contact the store owner 

via Skype.

 

I am currently getting this error:

"Fatal error: Cannot instantiate non-existent class: xmlparser"

 

This is the XML file I am trying to process:

================================================

<rdf:RDF>

<Status rdf:about="urn:skype:skype.com:skypeweb/1.1">

<statusCode rdf:datatype="http://www.skype.com/go/skypeweb">3</statusCode>

<presence xml:lang="NUM">3</presence>

<presence xml:lang="en">Away</presence>

<presence xml:lang="fr">Absent</presence>

<presence xml:lang="de">Abwesend</presence>

<presence xml:lang="ja">一時退席中</presence>

<presence xml:lang="zh-cn">暫時離開</presence>

<presence xml:lang="zh-tw">离开</presence>

<presence xml:lang="pt">Ausente</presence>

<presence xml:lang="pt-br">Ausente</presence>

<presence xml:lang="it">Torno subito</presence>

<presence xml:lang="es">Ausente</presence>

<presence xml:lang="pl">Zaraz wracam</presence>

<presence xml:lang="se">Tillfälligt borta</presence>

</Status>

</rdf:RDF>

==========================================

 

And this is what I have written so far:

==========================================

<?php

 

function print_error() {

    global $parser;

    die(sprintf("XML Error: %s at line %d",

        xml_error_string($xml_get_error_code($parser)),

        xml_get_current_line_number($parser)

    ));

}

 

//Get the XML document loaded into a variable

$status = file_get_contents('http://mystatus.skype.com/SkypeNameHere.xml');

 

//Set up the parser object

$parser = new XMLParser($status);

 

$parser->Parse();

 

//Display the results

{   

    //If the rating is 2

    if($presence->tagAttrs['NUM'] == '2')

        echo ('<a href="skype:SkypeNameHere?call"><img src="www.somewhere.com/images/online.gif" style="border: none;" width="140" height="56" alt="Available" /></a>');

 

    //If the rating is not 2

    if($presence->tagAttrs['NUM'] != '2')

        echo ('<img src="www.somewhere.com/images/not_online.gif" style="border: none;" width="140" height="56" alt="Not Available" />');

}

 

?>

===================================================

 

Hope you can help me set this up.

 

Kind regards, and many thanks,

 

Goshawk

 

 

Link to comment
Share on other sites

The code comes from a mixture of the php manual and some learning modules I found online.

 

I can call the file both in xml, txt or return a num value. What need to know is, once I have called that file, how do I process it contents, so I can create an output to display online.

Link to comment
Share on other sites

Hi jesirose,

 

Sorry I have not been in contact till now, but as you would have noticed, the server went down for a bit.

As a newbie, I was looking for things far too complicated. Instead of the more complex xml file, I decided to call the data from a *.num file which gives a return of one digit (0, 1, 2, 3, 4, 5, 6). A return of '2' means that the user is online and available. I am only interested to know whether the user is available, so therefore I need to post only one of 2 replies; either 'available' or 'not available'

 

Below is the simple code:

<?php

$content = file_get_contents("http://mystatus.skype.com/SkypeUserName.num");
if ($content == '2')
	echo '<a href="skype:SkypeUserName?call"><img src="./images/skype/online.gif" style="border: none;" width="140" height="56" alt="Available" /></a>';
   
	if ($content != '2')
       		echo '<img src="./images/skype/not_online.gif" style="border: none;" width="140" height="56" alt="Not Available" />';
?>

 

I now have encountered a second problem (beside the image not loading due to wrong url) and that is to define '$content' as seen in the code below.

<?php

  $show_SkypeLive = true;

  if ($show_SkypeLive == true) {
    $content = '';
    require($template->get_template_dir('tpl_SkypeLive.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_SkypeLive.php');
    
    $content = #[color=red]what should I put here?[/color];

    $title =  BOX_HEADING_SkypeLive;
    $title_link = false;
    $left_corner = false;
    $right_corner = false;
    $right_arrow = false;
    require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
}
?>

 

The result of this code can be seen here: http://www.inekesfashions.com.au/wholesale/

 

As you can see, this code displays the results of the first line of code in the sidebox, and what I need to have displayed is shown above the sidebox.

$content should also be 'class=sideBoxContent centerBoxContent' so that is displays according to the css.

 

How must I define '$content' and how do I prevent the results to be displayed from '$content = file_get_contents("http://mystatus.skype.com/SkypeUserName.num");'

 

Thanks for your time,

 

Goshawk

 

 

Link to comment
Share on other sites

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.