oracle dom xml

create or replace procedure sys.change_xml (dir varchar2)
--节点对节点元素对元素
--DOCUMENT为最大结点
is
doc xmldom.DOMDocument;
main_node xmldom.DOMNode;
root_ele xmldom.DOMElement;
root_node xmldom.DOMNode;
item_node xmldom.DOMNode;
item_ele xmldom.DOMElement;
item_text xmldom.DOMText;
stu_node xmldom.DOMNode;
cursor student_recordes(num number) is
select rownum,sno,sname,age from student where rownum<=num;
begin
doc:=xmldom.newDOMDocument;--创建新的文档
main_node:=xmldom.makeNode(doc);--最大父结点为DOC
root_ele:=xmldom.createElement(doc,'studentes');--新建一个元素属于DOC的
root_node:=xmldom.appendChild(main_node,xmldom.makeNode(root_ele));--把元素变成结点并加在父结点之中
for stu_record in student_recordes(3) loop
/*
 item_ele:=xmldom.createElement(doc,'rownum');
 item_node:=xmldom.appendChild(root_node,xmldom.makeNode(item_ele));
 item_text:=xmldom.createTextNode(doc,stu_record.rownum);
 item_node:=xmldom.appendChild(item_node,xmldom.makeNode(item_text));
 */
 item_ele:=xmldom.createElement(doc,'student');
 xmldom.setAttribute(item_ele,'number',stu_record.rownum);
 stu_node:=xmldom.appendChild(root_node,xmldom.makeNode(item_ele));
 --------------------------------------------------------------------
 item_ele:=xmldom.createElement(doc,'sno');
 item_node:=xmldom.appendChild(stu_node,xmldom.makeNode(item_ele));
 item_text:=xmldom.createTextNode(doc,stu_record.sno);
 item_node:=xmldom.appendChild(item_node,xmldom.makeNode(item_text));
 ------------------------------------------------------------------------
 item_ele:=xmldom.createElement(doc,'sname');
 item_node:=xmldom.appendChild(stu_node,xmldom.makeNode(item_ele));
 item_text:=xmldom.createTextNode(doc,stu_record.sname);
 item_node:=xmldom.appendChild(item_node,xmldom.makeNode(item_text));
 ----------------------------------------------------------------------
 item_ele:=xmldom.createElement(doc,'age');
 item_node:=xmldom.appendChild(stu_node,xmldom.makeNode(item_ele));
 item_text:=xmldom.createTextNode(doc,stu_record.age);
 item_node:=xmldom.appendChild(item_node,xmldom.makeNode(item_text));
 ------------------------------------------------------------------
end loop;
xmldom.writeToFile(doc,dir);
xmldom.freeDocument(doc);
end change_xml;
/

你可能感兴趣的:(oracle,xml)