Hi.
I don't have an 8i instance to work on so I've used 10g, and used the contents of the 9i version of that article as a base. See:
http://www.oracle-base.com/articles/...ocuments9i.php
Anyway, I saved your XML to a file called users.xml and ran this code.
When I run this I get this:Code:CREATE DIRECTORY xml_dir AS 'c:\'; SET SERVEROUTPUT ON DECLARE l_bfile BFILE; l_clob CLOB; l_parser dbms_xmlparser.Parser; l_doc dbms_xmldom.DOMDocument; l_attrs dbms_xmldom.DOMNamedNodeMap; l_attr dbms_xmldom.DOMNode; l_nl dbms_xmldom.DOMNodeList; l_n dbms_xmldom.DOMNode; l_text VARCHAR2(32767); BEGIN l_bfile := BFileName('XML_DIR', 'users.xml'); dbms_lob.createtemporary(l_clob, cache=>FALSE); dbms_lob.open(l_bfile, dbms_lob.lob_readonly); dbms_lob.loadFromFile(dest_lob => l_clob, src_lob => l_bfile, amount => dbms_lob.getLength(l_bfile)); dbms_lob.close(l_bfile); -- make sure implicit date conversions are performed correctly dbms_session.set_nls('NLS_DATE_FORMAT','''DD-MON-YYYY'''); -- Create a parser. l_parser := dbms_xmlparser.newParser; -- Parse the document and create a new DOM document. dbms_xmlparser.parseClob(l_parser, l_clob); l_doc := dbms_xmlparser.getDocument(l_parser); -- Free resources associated with the Parser now it is no longer needed. dbms_xmlparser.freeParser(l_parser); l_n := dbms_xslprocessor.selectSingleNode(xmldom.makeNode(l_doc),'/Access/User'); l_attrs := dbms_xmldom.getattributes(l_n); FOR cur_attr IN 0 .. dbms_xmldom.getLength(l_attrs) - 1 LOOP l_attr := dbms_xmldom.item(l_attrs, cur_attr); DBMS_OUTPUT.put_line(dbms_xmldom.getNodeName(l_attr) || '=' || dbms_xmldom.getNodeValue(l_attr)); END LOOP; l_n := dbms_xslprocessor.selectSingleNode(xmldom.makeNode(l_doc),'/Access/User/BasicSignon'); DBMS_OUTPUT.put_line(dbms_xmldom.getNodeName(l_n) || '=' || dbms_xmldom.getNodeValue(dbms_xmldom.getFirstChild(l_n))); -- Get a list of all the EMP nodes in the document using the XPATH syntax. l_nl := dbms_xslprocessor.selectNodes(xmldom.makeNode(l_doc),'/Access/User/Userclasses/Userclass'); -- Loop through the list and create a new record in a tble collection -- for each EMP record. FOR cur_uc IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP l_n := dbms_xmldom.item(l_nl, cur_uc); l_attrs := dbms_xmldom.getattributes(l_n); l_attr := dbms_xmldom.item(l_attrs, 0); DBMS_OUTPUT.put_line(dbms_xmldom.getNodeName(l_attr) || '=' || dbms_xmldom.getNodeValue(l_attr)); END LOOP; -- Free any resources associated with the document now it -- is no longer needed. dbms_xmldom.freeDocument(l_doc); END; /
I'm sure you could chop some of the crap out, but I'm a bit rushed for time.Code:[email protected] phone=+44 (0) 999 999 9999 first_name=fname name=fname lname last_name=lname BasicSignon=loginA name=Site User name=European Admin name=Sales Admin PL/SQL procedure successfully completed.
Cheers
Tim...




Reply With Quote