简体   繁体   English

我希望将 javascript 中该函数的函数名称和主体解析为一个单独的文件。 我如何使用 Java 做到这一点?

[英]I want the function name and body of that function from a javascript to get parsed out into a separate file. How do I do that using Java?

I have the following sample code:我有以下示例代码:

 <Script> var lastEntdFld ; var fldobj ; var Args ; var errormsg ; function InitJSvar(){ try { //Some texts }catch(e){} } </script>

After parsing I want the following code:解析后我想要以下代码:

function InitJSvar(){
   try {
        //Some texts
       }catch(e){}
    }

How can I do that using Java?我如何使用 Java 做到这一点?

You can achieve this by writing your own Parser for javascript and exporting the result into a new file with a filewriter.您可以通过为 javascript 编写自己的解析器并使用文件编写器将结果导出到新文件中来实现这一点。 I think this would be the easiest way to do it.我认为这将是最简单的方法。

Also if your script is in a HTML You can use JSOUP and manual parsing.此外,如果您的脚本在 HTML 中,您可以使用JSOUP和手动解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在另一个JS文件中调用全局函数。 我如何获得“这个”的作用? - Calling a global function in another JS file. How do I get 'this' to work? 我如何从此Firebase集合查询功能中获取“ retArr”数组。 我想将数组值用于其他功能 - How do i get the “retArr” array out from this firebase collection query function. I want the array values to used for another function 如何将javascript函数锁定到本地范围?我想阻止它使用全局变量 - How do I Lock a javascript function to the local scope ? I want to prevent it from using global variables 如何从javascript函数中获取数据 - how do I get the data out of a javascript function 如何跳出 javascript 中的函数 - How do I break out of a function in javascript 如何使用Javascript将数组vlaue从函数中传递出去 - How do I pass an Array vlaue out of a function using Javascript 我如何从 javascript 函数调用 java 类对象?(没有 ajax) - how do i call java class object from javascript function?(with out ajax) 如何从 function 中获取数组? - How do I get an array out of a function? 如何通过复选框将名称放入JavaScript getElementById函数中 - How do I put the name in JavaScript getElementById function from the checkbox 如何分离JavaScript的常量? - How do I separate out constants for JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM