I have written so please correct if something can be improved or corrected.
DECLARE
g_doc dbms_xmldom.DOMDocument; -- basic DOM-document
g_node dbms_xmldom.DOMNode;
g_new_el dbms_xmldom.DOMElement;
g_nlist dbms_xmldom.DOMNodeList; -- list of child nodes
g_clob clob;
g_cnum integer default 0;
g_cchar integer default 0;
g_cdeltags integer default 0;
-- The procedure for manipulating the attributes of a node
procedure manipulation_node_attributes (p_node in dbms_xmldom.DOMNode) is
l_nattrs dbms_xmldom.DOMNamedNodeMap; -- the list of attributes node
l_node dbms_xmldom.DOMNode; -- the type of node - the attribute
l_elem dbms_xmldom.DOMElement;
l_tmp_Attr dbms_xmldom.DOMAttr;
l_sattrs varchar2 (2000); -- Name of the attribute
l_vattrs varchar2 (2000); -- the value of the attribute
l_nval varchar2 (2000); -- the value of the node
l_nnam varchar2 (2000); -- the host name
l_nattrs_len integer;
l_nattrs_del integer default 0;
begin
-- Get the attributes of a node
l_elem: = dbms_xmldom.makeElement (p_node);
l_nattrs: = dbms_xmldom.GetAttributes (p_node);
-- /*
-- Manipulation with attribute values
if not dbms_xmldom.isNull (l_nattrs) then
l_nattrs_len: = dbms_xmldom.GetLength (l_nattrs) - 1;
while (l_nattrs_len + 1! = l_nattrs_del) /* and (l_nattrs_len> = 0) */
loop
l_node: = dbms_xmldom.item (l_nattrs, l_nattrs_del);
l_sattrs: = dbms_xmldom.GetNodeName (l_node);
l_vattrs: = dbms_xmldom.GetNodeValue (l_node);
-- Number - delete
if (isnumber (l_vattrs)) then
l_tmp_Attr: = dbms_xmldom.getAttributeNode (l_elem, l_sattrs);
l_tmp_Attr: = dbms_xmldom.removeAttributeNode (l_elem,
l_tmp_Attr);
l_nattrs_len: = l_nattrs_len - 1;
g_cnum: = g_cnum + 1;
-- Text - uppercase
else
dbms_xmldom.setNodeValue (l_node, upper (l_vattrs));
g_cchar: = g_cchar + 1;
l_nattrs_del: = l_nattrs_del + 1;
end if;
end loop;
end if;
-- */
end;
-- A recursive procedure for constructing the DOM tree of the document
procedure tree_manipulation_node_element (p_node in dbms_xmldom.DOMNode) is
l_nlist dbms_xmldom.DOMNodeList; -- list of child nodes
l_node dbms_xmldom.DOMNode; -- the current node
l_next_node dbms_xmldom.DOMNode; -- the current node 1
l_del_node dbms_xmldom.DOMNode; -- delete the current node
l_nval varchar2 (2000); -- the value of the node
l_nnam varchar2 (2000); -- name node
l_nlist_len number;
begin
-- Open the node description
dbms_output.put_line ('start:' | | dbms_xmldom.getNodeName (p_node));
-- Manipulation of the attributes node
manipulation_node_attributes (p_node);
-- Repeat the steps you
if dbms_xmldom.hasChildNodes (p_node) then
l_node: = dbms_xmldom.getFirstChild (p_node);
l_next_node: = l_node;
while not dbms_xmldom.isNull (l_next_node) loop
if (dbms_xmldom.getNodeType (l_node) = 1) then
tree_manipulation_node_element (l_node);
end if;
l_next_node: = dbms_xmldom.getNextSibling (l_node);
if ((not dbms_xmldom.hasAttributes (l_node)) and
(Dbms_xmldom.getNodeType (l_node) = 1) and dbms_xmldom.getNodeName (dbms_xmldom.getParentNode (l_node))! = '#document') then
if ((not dbms_xmldom.hasChildNodes (l_node))) or (dbms_xmldom.hasChildNodes (l_node) and
(Dbms_xmldom.getNodeType (dbms_xmldom.getFirstChild (l_node))! = 1)) then
dbms_output.put_line ('deleted: ---->' | |
dbms_xmldom.getNodeName (l_node));
l_del_node: = dbms_xmldom.removeChild (dbms_xmldom.getParentNode (l_node),
l_node);
g_cdeltags: = g_cdeltags + 1;
end if;
end if;
l_node: = l_next_node;
end loop;
end if;
-- Close the node description
dbms_output.put_line ('Endof:' | | DBMS_XMLDOM.getNodeName (p_node));
end;
BEGIN
for cur in (select num_id, before_xml
from xmldom_sidor
/* Where num_id = 4 */
order by num_id) loop
select cur.before_xml into g_clob from dual;
g_cnum: = 0;
g_cchar: = 0;
g_cdeltags: = 0;
-- Building a tree
g_doc: = dbms_xmldom.newDOMDocument (g_clob);
g_node: = dbms_xmldom.makeNode (g_doc);
tree_manipulation_node_element (g_node);
g_nlist: = dbms_xmldom.getChildNodes (g_node);
g_node: = dbms_xmldom.item (g_nlist, 0);
-- Adding a new element and attribute
g_new_el: = dbms_xmldom.createElement (g_doc, 'MODIFICATIONS');
dbms_xmldom.setAttribute (g_new_el, 'nums', g_cnum);
dbms_xmldom.setAttribute (g_new_el, 'chars', g_cchar);
dbms_xmldom.setAttribute (g_new_el, 'del_tags', g_cdeltags);
g_node: = dbms_xmldom.appendChild (g_node,
dbms_xmldom.makeNode (g_new_el));
dbms_xmldom.writeToClob (g_doc, g_clob);
update xmldom_sidor x
set x.after_xml = g_clob
where x.num_id = cur.num_id;
dbms_xmldom.freeDocument (g_doc);
end loop;
END;