CREATE OR REPLACE PACKAGE BODY xpath_rules_admin AS PROCEDURE addRuleSet( doc xmldom.DOMDocument ) IS -- (1) Declare handy record variables to work with theRuleSet ruleset%ROWTYPE; theRule rule%ROWTYPE; theRules xmldom.DOMNodeList; curRuleNode xmldom.DOMNode; BEGIN -- (2) Get the name of the ruleset being added theRuleSet.name := xpath.valueOf(doc,'/ruleset/@name'); DropRuleSet(theRuleSet.name); -- (3) Get a new ruleset id and insert the new ruleset SELECT ruleset_seq.nextval INTO theRuleSet.id FROM DUAL; INSERT INTO ruleset(id,name) VALUES (theRuleSet.id, theRuleSet.name); -- (4) Get a list of all <rule> elements under <ruleset> theRules := xpath.selectNodes(doc,'/ruleset/rule'); -- (5) Loop over the list of <rule> elements we found FOR j IN 1..xmldom.getLength(theRules) LOOP -- (6) Get the j-th rule in the list (zero-based!) curRuleNode := xmldom.item(theRules,j-1); theRule.ruleset := theRuleSet.id; -- (7) Get the name of the current rule theRule.name := xpath.valueOf(curRuleNode,'@name'); -- (8) Get the normalized value of the current rule element ('.') theRule.xpath_test := xpath.valueOf(curRuleNode,'.',normalize=>TRUE); -- (9) Insert the current rule into the rule table INSERT INTO rule(ruleset,name,xpath_test) VALUES (theRule.ruleset, theRule.name, theRule.xpath_test); END LOOP; COMMIT; END; PROCEDURE dropRuleSet( ruleset_name VARCHAR2 ) IS BEGIN DELETE FROM ruleset WHERE name = ruleset_name; COMMIT; END; END; |