PROCEDURE xml_perse (
errbuf OUT VARCHAR2,
retcode OUT NUMBER,
dir VARCHAR2,
inpfile VARCHAR2
)
IS
p xmlparser.parser;
doc xmldom.domdocument;
docelem DBMS_XMLDOM.domelement;
-- prints elements in a document
BEGIN
-- new parser
p := xmlparser.newparser;
-- set some characteristics
xmlparser.setvalidationmode (p, FALSE);
fnd_file.put_line (fnd_file.LOG, ' xml_perse Validated');
--xmlparser.setErrorLog(p, dir || '/' || errfile);
xmlparser.setbasedir (p, dir);
fnd_file.put_line (fnd_file.LOG, ' xml_perse set path');
-- parse input file
xmlparser.parse (p, dir || '/' || inpfile);
fnd_file.put_line (fnd_file.LOG, ' xml_perse parse');
-- get document
doc := xmlparser.getdocument (p);
fnd_file.put_line (fnd_file.LOG, ' xml_perse get document');
-- Print document elements
DBMS_OUTPUT.put ('The elements are: ');
printelements (doc);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
--SQLERRM
DBMS_OUTPUT.put (SQLERRM);
END xml_perse;
PROCEDURE printelements (doc xmldom.domdocument)
IS
nl1 xmldom.domnodelist;
nl2 xmldom.domnodelist;
nl3 xmldom.domnodelist;
nl4 xmldom.domnodelist;
nl5 xmldom.domnodelist;
len1 NUMBER;
len2 NUMBER;
len3 NUMBER;
len4 NUMBER;
len5 NUMBER;
n1 xmldom.domnode;
n2 xmldom.domnode;
n3 xmldom.domnode;
n4 xmldom.domnode;
nnm xmldom.domnamednodemap;
attrname VARCHAR (1000);
attrval VARCHAR (1000);
v_empid VARCHAR2 (1000);
v_emp_full_name VARCHAR2 (1000);
v_designation VARCHAR2 (1000);
BEGIN
-- get all elements
fnd_file.put_line (fnd_file.LOG, 'get all elements');
nl1 := xmldom.getelementsbytagname (doc, 'record');
nl2 := xmldom.getelementsbytagname (doc, 'EmpID');
nl3 := xmldom.getelementsbytagname (doc, 'vcEmp_Full_Name');
nl4 := xmldom.getelementsbytagname (doc, 'vcDesignation');
fnd_file.put_line (fnd_file.LOG, 'Length of the Elements');
--- Length of the Elements
len1 := xmldom.getlength (nl1);
len2 := xmldom.getlength (nl2);
len3 := xmldom.getlength (nl3);
len4 := xmldom.getlength (nl4);
-- loop through elements
FOR i IN 0 .. len1 - 1
LOOP
v_empid := NULL;
v_emp_full_name := NULL;
v_designation := NULL;
n1 := xmldom.item (nl1, i);
n2 := xmldom.item (nl2, i);
n3 := xmldom.item (nl3, i);
n4 := xmldom.item (nl4, i);
v_empid := xmldom.getnodevalue (n2);
v_emp_full_name := xmldom.getnodevalue (n3);
v_designation := xmldom.getnodevalue (n4);
fnd_file.put_line (fnd_file.LOG, '***************************');
fnd_file.put_line (fnd_file.LOG, v_empid);
fnd_file.put_line (fnd_file.LOG, v_emp_full_name);
fnd_file.put_line (fnd_file.LOG, v_designation);
fnd_file.put_line (fnd_file.LOG, '***************************');
DELETE FROM xx_employee_temp;
--WHERE status = 'S';
INSERT INTO xx_employee_temp
(empid, emp_full_name, designation,status, error_description
)
VALUES (v_empid, v_emp_full_name, v_designation,NULL, NULL
);
DBMS_OUTPUT.put_line (' ');
END LOOP;
fnd_file.put_line (fnd_file.LOG, 'Inserted');
END printelements;