SET SERVEROUTPUT ON DECLARE newsURL VARCHAR2(80); parser xmlparser.Parser; newsXML xmldom.DOMDocument; titles xmldom.DOMNodeList; titles_found NUMBER; curNode xmldom.DOMNode; textChild xmldom.DOMNode; BEGIN dbms_output.put_line('Top Stories on XML from Moreover.com on '|| TO_CHAR(SYSDATE,'FMMonth ddth, YYYY')); -- This is the URL to browse for an XML-based news feed of stories on XML newsURL := 'http://p.moreover.com/cgi-local/page?index_xml+xml'; -- Set the machine to use as the HTTP proxy server for URL requests http_util.setProxy('yourproxyserver.you.com'); -- Parse the live XML news feed from Moreover.com by URL parser := xmlparser.newParser; newsXML := xmlparser.parse( newsURL ); xmlparser.freeParser(parser); -- Search for all <headline_text> elements in the document we recieve titles := xmldom.getElementsByTagName(newsXML,'headline_text'); -- Loop over the "hits" and print out the text of the title FOR j IN 1..xmldom.getLength(titles) LOOP -- Get the current <headline_text> node (Note the list is zero-based!) curNode := xmldom.item(titles,j-1); -- The text of the title is the first child (text) node of -- the <headline_text> element in the list of "hits" textChild := xmldom.getFirstChild(curNode); dbms_output.put_line('('||LPAD(j,2)||') '||xmldom.getNodeValue(textChild)); END LOOP; -- Free the XML document full of news stories since we're done with it. xmldom.freeDocument(newsXML); END; |