HI,
I have the following script code in coldfusion (CFM), can anyone helpme to change the below script code to C# or java script.
http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?tool=CogentMedicineWebSite&email=cogentmedicine@acr.org&dbfrom=pubmed&id=1[
^]
The above link will gives you XML content.
The Function ReadLinkoutReply(strInput) will pass the xml file content as a parameter.
Need to separate the Publishers,Libraries,Aggregators in that xml.
please help me.....
<cfscript>
function MunchTag(strTag, objInput)
{
var emark = 0;
var smark = 0;
var tagLen = 0;
if(objInput.offset eq 0)
{
smark = Find("<" & strTag & ">", objInput.data);
emark = Find("</" & strTag & ">", objInput.data);
}
else
{
smark = Find("<" & strTag & ">", objInput.data, objInput.offset);
emark = Find("</" & strTag & ">", objInput.data, objInput.offset);
}
if((smark eq 0) or (emark eq 0))
{
objInput.finished = true;
return "";
}
tagLen = Len(strTag);
objInput.offset = emark + tagLen + 3;
smark = smark + tagLen + 2; // move past the opening tag
return Mid(objInput.data, smark, emark-smark);
}
function NewReply(strReply)
{
var inStream = StructNew();
inStream.data = strReply;
inStream.offset = 0;
inStream.finished = false;
return inStream;
}
function MunchOneTag(strTag, strInput)
{
var inStream = NewReply(strInput);
return MunchTag(strTag, inStream);
}
function ReadLink(objInput)
{
var bkmk = 0;
var str = "";
var strTag = "";
var objTag = StructNew(); // this will be thrown away (how else to you initialize this?)
var link = StructNew();
link.isValid = false;
strTag = MunchTag("ObjUrl", objInput);
If(objInput.finished)
{
return link;
}
//create a separate stream object for the link tag
//this prevents us from running past the end and into the next
objTag = NewReply(strTag);
str = MunchTag("Url", objTag);
if(objInput.finished)
{
return link;
}
//convert relative links
if(Mid(str, 1, 1) EQ "/")
{
str = "http://www.ncbi.nlm.nih.gov" & str;
}
link.url = str;
// minimum valid tag consists of a link
link.isValid = true;
link.subjects = ArrayNew(1);
link.attributes = ArrayNew(1);
bkmk = objTag.offset;
str = MunchTag("LinkName", objTag);
if(objTag.finished)
{
objTag.offset = bkmk;
objTag.finished = false;
link.name = "No Name";
link.useName = false;
}
else
{
link.name = str;
link.useName = true;
}
bkmk = objTag.offset;
for(str=MunchTag("SubjectType", objTag);objTag.finished EQ false; str=MunchTag("SubjectType", objTag))
{
ArrayAppend(link.subjects, str);
}
objTag.offset = bkmk;
objTag.finished = false;
for(str=MunchTag("Attribute", objTag); objTag.finished EQ false; str=MunchTag("Attribute", objTag))
{
ArrayAppend(link.attributes, str);
}
objTag.offset = bkmk;
objTag.finished = false;
str = MunchTag("Provider", objTag);
link.provider = ReadProvider(NewReply(str));
return link;
}
function ReadProvider(objProv)
{
var str = "";
var rv = StructNew();
str = MunchTag("Name", objProv);
rv.name = str;
str = MunchTag("Id", objProv);
rv.id = str;
str = MunchTag("Url", objProv);
rv.url = str;
str = MunchTag("IconUrl", objProv);
if(objProv.finished)
{
rv.icon = "none";
rv.useIcon = false;
}
else
{
if(Mid(str, 1, 6) EQ "DB__ft")
{
// not sure what this is about, but there are many IconURLs that refer to
// gif files with no domain or path, and all start with "DB__ft"
rv.icon = "none";
rv.useIcon = false;
}
else
{
rv.icon = str;
rv.useIcon = true;
}
}
return rv;
}
function ReadLinkoutReply(strInput)
{
var strFullSet = "";
var loURLs = StructNew();
var urlList = StructNew();
var thisLink = StructNew();
var fullSet = NewReply(strInput);
loURLs.links = ArrayNew(1);
loURLs.count = 0;
strFullSet = MunchTag("IdUrlSet", fullSet);
if(fullSet.finished)
{
// error - can't find tag or ended prematurely
loURLs.error = True;
// to do: look for error description
return loURLs;
}
loURLs.error = False;
urlList = NewReply(strFullSet);
// 250 link limit is simply to guarantee script termination
// this could be raised or even eliminated - if you're feeling lucky
for(i=1; i LT 250; i = i + 1)
{
thisLink = ReadLink(urlList);
if(thisLink.isValid)
{
loURLs.links[i] = thisLink;
loURLs.count = i;
}
else
{
break;
}
}
// PDK: code in transition. We still collect all subjects, but for now
// we're only going to display publishers, libraries, and aggregators
loURLs.subjects = "";
loURLs.publishers = ArrayNew(1);
loURLs.libraries = ArrayNew(1);
loURLs.aggregators = ArrayNew(1);
for(i=1; i LTE ArrayLen(loURLs.links); i = i + 1)
{
for(j=1; j LTE ArrayLen(loURLs.links[i].subjects); j=j+1)
{
if(ListFind(loURLs.subjects, loURLs.links[i].subjects[j]) EQ 0)
{
loURLs.subjects = ListAppend(loURLs.subjects, loURLs.links[i].subjects[j]);
}
if(loURLs.links[i].subjects[j] EQ "publishers/providers")
{
ArrayAppend(loURLs.publishers, loURLs.links[i]);
}
else if(loURLs.links[i].subjects[j] EQ "libraries")
{
ArrayAppend(loURLs.libraries, loURLs.links[i]);
}
else if(loURLs.links[i].subjects[j] EQ "aggregators")
{
ArrayAppend(loURLs.aggregators, loURLs.links[i]);
}
}
}
loURLs.subjects = ListSort(loURLs.subjects, 'text');
return loURLs;
}
</cfscript>
Thanks in Advance....