Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2012, 04:16 PM   PM User | #1
pawar
New to the CF scene

 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
pawar is an unknown quantity at this point
to exculde some search terms in the xml code

Hi,


I have an xml code which searches for names in a webpage and checks against a article content. Now i have certain names in this webpage which need to be excluded for the search.

my code goes like this=

Code:
<Content type="html" view="profile">
    <![CDATA[
    <script type="text/javascript">
		
		//This will hold all the drug code
		//The key/index will be the drug names
		var drugReference = [];		
		//The url using which master list of drugs can be downloaded
		var drugListUrl = "http://rest.kegg.jp/list/drug";
		//Prefix of the url using which specifications of a particular drug
		//can be fetched
		var drugSpecsUrlPrefix = "http://www.kegg.jp/entry/"
		//This will hold the entire article content
		var articleContent = "";

		//This method is used to make a call to retrieve the article content
		function getContent(){
		   gadgets.sciverse.getArticleContent(getContentCallback);
		}

		//The getContent callback function 
		//After retrieving the article content make a call to the function
		//that will link the drug names
		function getContentCallback(response){
			if (response != null){			
				articleContent = response.toUpperCase();				
				linkText();
			}else{
				alert("Sorry!!!. Unable to retrieve the article content");
			}			
		}
		
		//This method is used to make a request to get the entire list of drug names
		function linkText(){     		
			var params ;
			gadgets.sciverse.makeRequest(drugListUrl, requestCallBack, params);

        }

		//The makeRequest callback function
		function requestCallBack (response){
			//Get the contents of the drug listing
			var relevantData = response.text;
			//Each line represents a particular drug. 
			//Split and get each drug into an array
			var drugs = relevantData.split("\n");
			//Array to hold the terms to be linked in the article
			var terms  = [];

			for(var i=0; i < drugs.length; i++) {				
				//Each line will have a drug code and multiple drug names
				//seperated by a tab. Split the drug code and names first
				var drug = drugs[i].split('\t');
				var drugCode = drug[0];				
				var drugNames = drug[1].split(";");
				
				//Split the multiple drug names and map each name to the drug code
				for(var j = 0; j < drugNames.length ; j++){						
					var temp = drugNames[j].toUpperCase();
					//From the drug names, extract only the names
					//and exclude the words in the paranthesis
					//Ex : dr:D07380	Letosteine (INN); Viscotiol (TN)
					//we will extract only the  words LETOSTEINE
					//and VISCOTIOL and then map these to the drug code dr:D07380
					//we do not consider (INN) and (TN) which are part of the
					//drug names. This is because in an article we may not
					//find the terms such as the ones in the paranthesis
					var index = temp.indexOf("(");					
					if(index > 0){
						temp = temp.substring(0,index);
					}
					//Trim any extra whitespace characters and get the drug name
					var actDrugName = $.trim(temp);					
					//Store the drug code with the drug name as the key to it
					drugReference[actDrugName] = drugCode;
					//If the drug name is found in the article content
					//then add it to the list of terms to be linked
					if(articleContent.indexOf(actDrugName) > 0){
						terms.push(actDrugName);
					}
				}
			}
			
			//other required parameters to be used while linking
            var categories = ["all"];
            var frequency = "every";
            var occurrence = 1;
            
            // Link the drug names that have been added to the terms array
            gadgets.sciverse.linkText(terms,categories,frequency,occurrence,'linkTextCallback',linkTextCallback);

		}

        // The linkText callback function.
        function linkTextCallback(term, posx, posy){		
			var drugName = term.toUpperCase();
			//Get the drug code for the drug that has been selected
			var drugCode = drugReference[drugName]			
            //Open window with the specifications for the drug that is selected
			var drugSpecsUrl =drugSpecsUrlPrefix + drugCode;			
			window.open(drugSpecsUrl,'DrugSpecifications','fullscreen=1,resizable=1,scrollbars=1');
        }

        //Resize the gadget on load
        gadgets.util.registerOnLoadHandler(function() {gadgets.window.adjustHeight();});


The http://rest.kegg.jp/list/drug is the url where the list of names available and i need to excluded some so please tell me how would i omit that.


thanks

Last edited by WA; 07-12-2012 at 06:53 PM..
pawar is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:02 PM.


Advertisement
Log in to turn off these ads.