RSS源创建器——可以从其它来源读取文本并将其以RSS或者Atom的格式发布出去

import java.io.*;
public class Creater {
	public static void main(String[] args) throws IOException {
		String[] s = new String[3];
		s[0]=CreateItem("标题1", "www.baidu1.com", "thanks1");
		s[1]=CreateItem("标题2", "www.baidu2.com", "thanks2");
		s[2]=CreateItem("标题3", "www.baidu3.com", "thanks3");
		String XML = CreateXML(s);
		File f = new File(args[0]);
		FileOutputStream fos = new FileOutputStream(f);
		fos.write(XML.getBytes());
	}
	public static String CreateTitle(String title) {//创建title标签
		String ans = new String();
		ans+="<title>";
		ans+=title;
		ans+="</title>\r\n";
		return ans;
	}
	public static String CreateLink(String link) {//创建link标签
		String ans = new String();
		ans+="<link>";
		ans+=link;
		ans+="</link>\r\n";
		return ans;
	}
	public static String CreateDescription(String description) {//创建一个description标签
		String ans = new String();
		ans+="<description>";
		ans+=description;
		ans+="</description>\r\n";
		return ans;
	}
	public static String CreateItem(String title, String link, String description) {//将三个标签整合为item
		String ans = new String();
		ans+="<item>\r\n";
		ans+=CreateTitle(title);
		ans+=CreateLink(link);
		ans+=CreateDescription(description);
		ans+="</item>\r\n";
		
		return ans;
	}
	public static String CreateXML(String [] Items) {//item整合为XML
		String ans = new String ();
		ans+="<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n";
		ans+="<rss version=\"2.0\">\r\n";
		ans+="<channel>\r\n";
		for(int i=0;i<Items.length;i++) {
			ans+=Items[i];
		}
		ans+="</channel>";
		return ans;
	}
}

创建源,运行方法:黑框中输入java xxx(类名) xxx/xxx.rss;

比如 java Creater F:/a.rss

发布的话用JAVA略微麻烦,可以使用node.js

server.js

let http = require('http');
let url = require('url');
let util = require('util');
let fs = require('fs'); 

let server = http.createServer((req,res)=>{
  var pathname = url.parse(req.url).pathname; //获取url的pathname (/index.html)
  console.log("file:"+pathname.substring(1)) //将‘/’去掉
  fs.readFile(pathname.substring(1), function (err,data) { //fs模块加载文件
      if(err){
          res.writeHead(404,{
            'Content-Type':'text/html'
          });
      }else{
        res.writeHead(200,{
          'Content-Type':'text/html'
        });
        res.write(data.toString());
      }
      res.end();
  });

});

server.listen(3000,'127.0.0.1', ()=>{
  console.log("服务器已经运行,请打开浏览,输入:http://127.0.0.1:3000/ 来进行访问.")
});

刚刚生成的rss文件

<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<item>
<title>标题1</title>
<link>www.baidu1.com</link>
<description>thanks1</description>
</item>
<item>
<title>标题2</title>
<link>www.baidu2.com</link>
<description>thanks2</description>
</item>
<item>
<title>标题3</title>
<link>www.baidu3.com</link>
<description>thanks3</description>
</item>
</channel>

放在同一目录下,配好node.js开发环境在CMD中输入

node server.js

然后用浏览器访问localhost:3000/a.rss就能看到刚刚发布的东西

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值