本文介绍了需要使用Java脚本或C#代码转换ColdFusion脚本代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 HI, 我在coldfusion(CFM)中有以下脚本代码,任何人都可以帮助将以下脚本代码更改为C#或java脚本。 /> http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?tool=CogentMedicineWebSite&[email protected]&dbfrom=pubmed& id = 1 [ ^ ] 以上链接将为您提供XML内容。 /> 函数ReadLinkoutReply(strInput)将xml文件内容作为参数传递。 需要分开那个xml中的出版商,图书馆,聚合商。 请帮助我..... < cf script > 函数MunchTag(strTag,objInput) { var emark = 0; var smark = 0; var tagLen = 0; if(objInput.offset eq 0) { smark = Find(< & strTag & > ,objInput.data); emark =查找(< / & strTag & > ,objInput.data); } 其他 { smark =查找(< & strTag & > ,objInput.data,objInput.offset); emark =查找(< / & strTag & > ,objInput.data,objInput.offset); } if((smark eq 0)或(emark eq 0)) { objInput.finished = true; 返回; } tagLen = Len(strTag); objInput.offset = emark + tagLen + 3; smark = smark + tagLen + 2; //移过开头标签返回Mid(objInput.data,smark,emark-smark); } 函数NewReply(strReply) { var inStream = StructNew(); inStream.data = strReply; inStream.offset = 0; inStream.finished = false; 返回inStream; } 函数MunchOneTag(strTag,strInput) { var inStream = NewReply(strInput); 返回MunchTag(strTag,inStream); } 函数ReadLink(objInput) { var bkmk = 0; var str =; var strTag =; var objTag = StructNew(); //这将被丢弃(你怎么初始化它?) var link = StructNew(); link.isValid = false; strTag = MunchTag(ObjUrl,objInput); 如果(objInput.finished) {返回链接; } //为链接标签 //创建一个单独的流对象,这可以防止我们超越结束并进入下一个 objTag = NewReply( strTag); str = MunchTag(Url,objTag); if(objInput.finished) { return link; } //转换相对链接 if(Mid(str,1,1)EQ/) { str =http ://www.ncbi.nlm.nih.gov&海峡; } link.url = str; //最小有效标记包含一个链接 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 =没有名字; link.useName = false; } 其他 { 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)); 返回链接; } 函数ReadProvider(objProv) { var str =; var rv = StructNew(); str = MunchTag(名称,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; } 其他 { if(Mid(str,1,6)EQDB__ft) { //不确定这是什么关于,但有很多IconURL引用 //没有域或路径的gif文件,所有都以DB__ft开头 rv.icon =none; rv.useIcon = false; } 其他 { rv.icon = str; rv.useIcon = true; } } 返回rv; } 函数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) { //错误 - 无法找到标签或过早结束 loURLs.error = True; //要做:找错误描述 return loURLs; } loURLs.error = False; urlList = NewReply(strFullSet); // 250链接限制只是为了保证脚本终止 //这可以被提升甚至消除 - 如果你感觉很幸运 for(i = 1; i LT 250; i = i + 1) { thisLink = ReadLink(urlList); if(thisLink.isValid) { loURLs.links [i] = thisLink; loURLs.count = i; } 其他 {休息; } } // PDK:转换中的代码。我们仍然收集所有科目,但现在 //我们只会显示发布者,图书馆和聚合器 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] EQpublishers / providers) { ArrayAppend(loURLs.publishers,loURLs.links [i] ); } else if(loURLs.links [i] .subjects [j] EQlibraries) { ArrayAppend(loURLs.libraries,loURLs.links [i]) ; } else if(loURLs.links [i] .subjects [j] EQaggregators) { ArrayAppend(loURLs.aggregators,loURLs.links [i]) ; } } } loURLs.subjects = ListSort(loURLs.subjects,'text'); 返回loURLs; } < / cf 脚本 > 在此先感谢.. .. 解决方案 检查这个 .NET代码转换 - 将代码转换为ColdFusion到.NET [ ^ ] 推荐此链接 http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/ threadid:573 [ ^ ] 它表明: 引用: 一个人不应该试试这个因为 1.从一种语言转换为另外你不仅要知道了解代码的内容,还要理解为什么。有一些程序必须做的东西,一种语言做另外做的事情 不是 - 这是程序员解决这些问题的工作 限制。 2.在大多数情况下编写代码的代码是一件好事 - 但是 它也是有限的了解编写 原始代码的程序员(参见#1)。如果你得到的东西可以将CFML转换成C#,你最好在大多数情况下发送CFC而不是CFML,因为如果内存服务的话,C#会大量使用OOP概念和基于类的 编程。 3.任何时候考虑在两种语言之间移植应用程序 你需要花时间检查应用程序,看看你为什么 计划移植它以及你可能想要的升级或功能 计划。 问候..:) 使用xml文件,根据标记名获取列表并将其作为列表显示,并在不使用要在C#或java脚本代码中转换的相同函数。 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 protected]&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.... 解决方案 Check this.NET Code Conversion - Convert your code - ColdFusion to .NET[^]Refer this linkhttp://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:573[^]It states that:Quote:One should not try this because1. When converting from one language to another you have to not onlyunderstand the "what" of the code but also the "why". There are somethings that a program must do that one language does that another doesnot - it is the job of the programmer to work around thoselimitations.2. Code that writes code is a good and right thing in most cases - butit is also limited to the knowledge of the programmer that wrote theoriginal code (see #1). If you get something that will convert CFMLto C# you better be sending in CFC's and not CFML in most cases as, ifmemory serves, C# makes extensive use of OOP concepts and class-basedprogramming.3. Any time you look into porting an application between two languagesyou need to take the time to examine the app and see why you areplanning on porting it and what upgrades or features you may want toplan in.Regards..:)Using the xml files,fetched the lists based on the tagnames and makes it as a list and displayed without using the same functions to be converted in C# or java script code. 这篇关于需要使用Java脚本或C#代码转换ColdFusion脚本代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 14:48