我需要一个程序(bash、perl、ruby,这并不重要),它解析 html/xml 并执行标签函数并在标签之间传递文本作为参数。
例子:
脚本:
#!/bin/????
. /path/to/parser
title()
{
cowsay $1
}
exit
文件.html:
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
This is only a test.
<br/>
I hope it works!
</body>
</html>
用法:
./script file.html
结果:
 _______________ 
< Hello, World! >
 --------------- 
      \   ^__^
       \  (oo)\_______
          (__)\       )\/\
              ||----w |
              ||     ||
我的尝试:
- 一次读取一个字符的 bash 脚本。代码不够好,无法在此处显示。:(
 - 使用 Ruby 和 libxml 开发解决方案 - 还没有运气。:(