Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

dbms_xmldom.isNull() problem

396312Jun 6 2003 — edited Sep 1 2003
Hi All,

I'm working with the dbms_xmldom class to (eventually) process incoming XML from the middle tier and perform table updates based on it's contents. I'm planning on looping through an XML document structured like this:
<data>
<field id="1" actualValue="john"/>
<field id="2" actualValue="smith"/>
</data>

and processing each of the <field> elements. I'm having a problem with the dbms_xmldom.isNull() function when testing for a NULL dbms_xmldom.DOMNode object. The test works correctly when the node is not NULL, but as soon as it's testing a NULL node, an error is created:

ORA-31020: The operation is not allowed, Reason: Invalid pl/sql DOM Node hdl
ORA-06512: at "XDB.DBMS_XMLDOM", line 558
ORA-06512: at "XDB.DBMS_XMLDOM", line 581
ORA-06512: at "VICAP.ZZXML", line 33
ORA-06512: at line 3

If you step through the procedure created in the below code, you will see that as soon as ndField is NULL (following the getNextSibling() function the second loop iteration) an error is raised out of the dbms_xmldom.isNull() function.

Has anyone experienced this? Is there a bug in my code, or is this an oracle problem?

Thanks,
Brian

--- code below ---
CREATE OR REPLACE PROCEDURE zzXML AS
bXML CLOB := '<data><field id="1" actualValue="john"/><field id="2" actualValue="smith"/></data>';
XmlData xmltype := sys.xmltype.createxml(bXML);
xmlDoc dbms_xmldom.DOMDocument;
ndRoot dbms_xmldom.DOMNode;
ndData dbms_xmldom.DOMNode;
ndField dbms_xmldom.DOMNode;
ndField2 dbms_xmldom.DOMNode;
strOut VARCHAR2(1000);

BEGIN

xmlDoc := dbms_xmldom.newDOMDocument(XmlData);
ndData := dbms_xmldom.makeNode(xmlDoc);
ndRoot := dbms_xmldom.getFirstChild(ndData);
ndField := dbms_xmldom.getFirstChild(ndRoot);

dbms_output.put_line('ndData: ' || dbms_xmldom.getNodeName(ndData));
dbms_output.put_line('ndRoot: ' || dbms_xmldom.getNodeName(ndRoot));
dbms_output.put_line('ndField: ' || dbms_xmldom.getNodeName(ndField) ||
', value: ' || dbms_xmldom.getNodeValue(ndField));
LOOP
EXIT WHEN dbms_xmldom.isNull(ndField) = TRUE;
BEGIN
strOut := 'ndField: ' || dbms_xmldom.getNodeName(ndField) ||
', value: ' || dbms_xmldom.getNodeValue(ndField);

dbms_output.put_line(strOut);

ndField2 := dbms_xmldom.getNextSibling(ndField);
ndField := ndField2;

IF dbms_xmldom.isNull(ndField) = FALSE
THEN
strOut := 'ndField: ' || dbms_xmldom.getNodeName(ndField) ||
', value: ' || dbms_xmldom.getNodeValue(ndField) ||
'second test';
dbms_output.put_line(strOut);
END IF;
END;
END LOOP;
dbms_xmldom.freeDocument(xmlDoc);
END zzXML;



Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 29 2003
Added on Jun 6 2003
1 comment
956 views