⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aggregator.java

📁 Usefull sample codes for Java. Containt all type of programs.
💻 JAVA
字号:
import java.io.*;
import nu.xom.*;

public class Aggregator {
    public String[] title = new String[15];
    public String[] link = new String[15];
    public int count = 0;
    
    public Aggregator(String rssUrl) {
        try {
            // retrieve the XML document
            Builder builder = new Builder();
            Document doc = builder.build(rssUrl);
            // retrieve the document's root element
            Element root = doc.getRootElement();
            // retrieve the root's channel element
            Element channel = root.getFirstChildElement("channel");
            // retrieve the item elements in the channel
            if (channel != null) {
                Elements items = channel.getChildElements("item");
                for (int current = 0; current < items.size(); current++) {
                    if (count > 15) {
                        break;
                    }
                    // retrieve the current item
                    Element item = items.get(current);
                    Element titleElement = item.getFirstChildElement("title");
                    Element linkElement = item.getFirstChildElement("link");
                    title[current] = titleElement.getValue();
                    link[current] = linkElement.getValue();
                    count++;
                }
            }   
        } catch (ParsingException exception) {
            System.out.println("XML error: " + exception.getMessage());
            exception.printStackTrace();
        } catch (IOException ioException) {
            System.out.println("IO error: " + ioException.getMessage());
            ioException.printStackTrace();
        }
    }         
    
    public void listItems() {
        for (int i = 0; i < 15; i++) {         
            if (title[i] != null) {
                System.out.println("\n" + title[i]);
                System.out.println(link[i]);
                i++;
            }
        }
    }
    
    public static void main(String[] arguments) {
        if (arguments.length > 0) {
            Aggregator aggie = new Aggregator(arguments[0]);
            aggie.listItems();
        } else {
            System.out.println("Usage: java Aggregator rssUrl");
        }
    }
}      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -