Parsing XML
Parsing XML
/**********************************************************************/
-- THIS PROCEDURE READS THE INPUT GIVEN IN THE CLOB VARIABLE AND GETS THE ELEMEN
TS
-- AND PRINTS IT OUT FROM THE XML BUILD AND ALSO CAN READ THE XML FILE WITH FEW
MODIFICATIONS
/*******************************************************************************
***************/
P xmlparser.parser;
doc xmldom.DOMDocument;
/***************************************************************/
-- prints elements in a document
procedure printElements(doc xmldom.DOMDocument) is
nl xmldom.DOMNodeList;
len number;
n xmldom.DOMNode;
eleval VARCHAR2(40);
V_CLOB CLOB;
begin
-- get all elements
nl := xmldom.getElementsByTagName(doc, '*');
len := xmldom.getLength(nl);
-- loop through elements
for i in 0..len-1 loop
n := xmldom.item(nl, i);
--get the text node associated with the element node
n:= xmldom.getfirstchild(n);
if xmldom.getnodetype(n) = 3 then
--dbms_output.put_line ('node 3 val>> '||xmldom.getnodevalue(n));
V_CLOB := V_CLOB||CHR(10)||XMLDOM.GETNODEVALUE(N);
end if;
end loop;
dbms_output.put_line(' CLOB IN SAMPLE2 ' ||V_CLOB);
end printElements;
/***************************************************************/
-- prints the attributes of each element in a document
procedure printElementAttributes(doc xmldom.DOMDocument) is
nl xmldom.DOMNodeList;
len1 number;
len2 number;
n xmldom.DOMNode;
e xmldom.DOMElement;
nnm xmldom.DOMNamedNodeMap;
attrname varchar2(100);
attrval varchar2(100);
begin
-- get all elements
nl := xmldom.getElementsByTagName(doc, '*');
len1 := xmldom.getLength(nl);
-- loop through elements
for j in 0..len1-1 loop
n := xmldom.item(nl, j);
e := xmldom.makeElement(n);
-- get all attributes of element
nnm := xmldom.getAttributes(n);
if (xmldom.isNull(nnm) = FALSE) then
len2 := xmldom.getLength(nnm);
-- loop through attributes