Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.

Bin-Blog

Subscribing a feed in Google Reader using Firefox

The latest version of firefox has a feed preview feature. But subscribing a new feed in Google Reader using this feature leaves a little to be expected. If you use this feature to subscribe to feeds in the Google Reader, you must have come across the "Subscribe to Google Reader/Google Homepage" dilemma. I always want to subscribe to Google Reader - thats one extra click for me. But I found a way to overcome this.

Open a new tab and type in about:config in the address bar.

Type browser.contentHandlers in the Filter text box

Find the key name of the Google Reader property - in my system, it is 'browser.contentHandlers.types.2.title'. See image for clarification

The 'index' of the Google Reader, in my case is 2.

Right click on browser.contentHandlers.types.2.uri(the number must be the index of Google Reader in your system) and click Modify.

Enter the value...

http://www.google.com/reader/view/feed/%s

Now restart Firefox and try to subscribe to a feed - you will be taken to the google reader page directly. Then click on the "Subscribe" button on the top right corner to subscribe.

Read More...

XML Parser function for JavaScript - xml2array()

I have created a small function called 'xml2array()' that will take an XML document as the argument, parse it and return an associative array as the result. This array will contain the data of the XML file - which can be easily accessed - without resorting to writing codes with xml.childNode or node.nextSibiling or any other stuff like that. Take a look at the Demo page.

XML Parsing in JavaScript

One have to admit that parsing XML code in JavaScript is relatively easy. We already have a DOM parser in place and we can use the functions provided by it to parse the XML documents. The functions like getElementsByTagName() can be used to make parsing XML documents much easier.

Actionscript

Compare that with, say, ActionScript - they have no getElementsByTagName. This makes it much more difficult to parse XML documents. I was hoping that this function will make XML parsing easier for ActionScripters also. But before using this code in ActionScript, please note that I don't know ActionScript - I only know JavaScript - and since the two are very similar, I was hoping that my script will work in Flash too - since they need it much more than we do. But it don't - my script creates some errors in Flash - if any of you could get it working in flash, please let me know.

Code

Anyway, the script can still be used in JavaScript for parsing XML returns in Ajax scripts. So if you use XML as the response data format for your ajax program, be sure to get a copy of the code for xml2array.

Read More...

XUL-ing Around

I am trying to study XUL. For those who are not familiar with XUL, or (XML User-interface Language is a cross-platform language for describing user interfaces of applications. Currently it is used for creating extensions for Firefox and Mozilla browsers.

The GUI is created in a language similar to HTML and the coding is done in JavaScript. So learning it was very easy for me. The only problem is the file organization and some other complex operations. Nothing to worry about - I will get the hang of it after I code two or three extensions.

I am making a small extension as a training exercise. It is not over yet but will be over any time now - will let you know once a download able version is complete.

For those interested to know more, head over to http://www.xulplanet.com

Read More...

And now in Firefox - XML parsing.

So far I have created two apps that will parse a given XML file in javascript - Binny's Software DataBase and JASFER. Both these programs had the same crippling problem - neither worked in Firefox. The work very well in IE - but in firefox, they have this burning desire to crash and burn.

But not anymore - now both are working in both IE and Firefox. I don't know about the other browsers - but generally, if any page works on the above two browsers it passes my minimum requirements.

Some links that helped me solve the problem...

XML DOM parser Javascript RSS reader

The problem was that I was using absolute item reference - like this...

nodes = data.documentElement.childNodes.item(0).childNodes
alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes.item(0).nodeName
  + "\nFirst Item Value : " + nodes.item(0).childNodes[0].text);
What I should have used is the getElementsByTagName() function - like this...
nodes = xmlDoc.getElementsByTagName("item"); //Get all the 'item's
alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes[0].firstChild.nodeName
  + "\nFirst Item Value : " + nodes[0].firstChild.nodeValue);

I have created a small cross browser framework for loading XML file while creating these softwares. The code is given below. If you have any use for it, feel free to use it - release in GPL licence.

////////////////////////////// XML File Loading ///////////////////////////////
//Firefox only function - happens when a XML file is loaded
function loadHandler () {
  xmlProcessor(this); //Call the Commen function with 'this' data.
}

//Load the xml file - using different method for different browsers
function xmlLoad(xml_file) {
  //Initializations
  feed_id = 0;
  feed_total = 0;

  var xmlDocument = "";
  feed_file = xml_file;
  if(document.implementation.createDocument) {//Firefox
      xmlDocument = document.implementation.createDocument('', '', null);
      xmlDocument.load(xml_file);
 //This function will happen when the file is loaded
 xmlDocument.addEventListener('load', loadHandler, false);
  }
  else { //IE
      var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
      xmlDocument.async = false;
      var loadResult = xmlDocument.load(xml_file);
      if (loadResult) {
          // process xml document with DOM methods e.g.
          xmlProcessor(xmlDocument)
      } else {
          xmlError();
          return false;
      }
  }
  return true;
}

function xmlError() {
  alert("Some error has occurred!")
}

//Process the xml data
function xmlProcessor(xmlDoc) {
  if(!xmlDoc) {
      feedError();
  }

  //Do whatever you want with the XML data...
  nodes = xmlDoc.getElementsByTagName("item"); //Get all the 'item's
  alert("Length : " + nodes.length
  + "\nFirst Item : " + nodes[0].firstChild.nodeName
  + "\nFirst Item Value : " + nodes[0].firstChild.nodeValue);

}

xmlLoad("file.xml"); // Load the XML file.
Read More...

Jasfer or JAvaScript FEed Reader

Jasfer or Jasfer or JAvaScript FEed Reader

Another product off the assembly line - Jasfer or JAvaScript FEed Reader. This is a JavaScript program to read RSS feeds and display it in a HTML file. With the publicity AJAX has received, making this program was just a matter of time.

You can embed this software in your page with just a couple of lines - then any feed of your choice will be shown on your page. I made this software to be as customizable as possible - it is very easy to change its appearance using CSS styles. Adding more features is also just as easy. I have created a few demos - Jasfer Examples. Check them out.

That was the good news - the bad news is that as of yet, the script will only work in IE. I am trying to make it functional in Firefox. If you can't wait, just take the code and do it yourself. That would save me a lot of time - and as I said earlier, that is a very rare commodity these days. Any help in this department is greatly appreciated.

Now a bit on the technical details on how the script works. It uses the Microsoft's XML Parser(Microsoft.XMLDOM) and will extract all necessary info using the DOM structure. Currently, the script will work only for feeds that are in RDF and RSS format - that means no atom - which is very bad for me as my blog has an atom feed and I won't be able to show my blog entries in my main site. I will try to add this feature as soon as possible - as I am very much dependent on it.

The to do list is given below. Again, any help is appreciated.

  • Make it object oriented
  • Firefox compactable
  • Documentation(I am going to hate this part)
  • More themes - some professional ones.
Read More...

Subscribe to : Posts