bilpar
asked on
Oracle XMLDOM - How do I update a node text value using dbms_xmldom.setNodeValue()?
Hello Experts,
When a node text value is null, how do I update a node text value using dbms_xmldom.setNodeValue() method? The code below runs in 10g. The <NAME> node updates. But, the <NAME2> node does not. Do i need to add a text node to <NAME2> first? How? Is there another way?
declare
var XMLType;
buf clob;
l_xmldoc dbms_xmldom.DOMDocument;
l_root dbms_xmldom.DOMNode;
l_node dbms_xmldom.DOMNode;
begin
var := xmltype('<PERSON> <NAME>ChangeMe</NAME> <NAME2></NAME2> </PERSON>');
-- Create DOMDocument handle:
l_xmldoc := dbms_xmldom.newDOMDocument (var);
l_root := dbms_xmldom.makeNode(l_xml doc);
-- before
dbms_xmldom.writetobuffer( l_root, buf);
dbms_output.put_line('Befo re:');
dbms_output.put_line(buf);
-- replace name.text
l_node := dbms_xslprocessor.selectSi ngleNode(l _root,'//N AME/text() ');
if dbms_xmldom.isnull(l_node) then
dbms_output.put_line('IsNu ll:');
dbms_xmldom.setNodeValue(l _node, 'node is null');
else
-- Manipulate:
dbms_xmldom.setNodeValue(l _node, 'raj');
end if;
-- replace name2.text... how is this done when the text node is null?
l_node := dbms_xslprocessor.selectSi ngleNode(l _root,'//N AME2/text( )');
if dbms_xmldom.isnull(l_node) then
dbms_output.put_line('IsNu ll: And, setNodeValue() does nothing to <NAME2>');
dbms_xmldom.setNodeValue(l _node, 'node is null');
else
-- Manipulate:
dbms_xmldom.setNodeValue(l _node, 'node is not null');
end if;
-- after
dbms_xmldom.writetobuffer( l_root, buf);
dbms_output.put_line('Afte r:');
dbms_output.put_line(buf);
end;
the code above yields the following output:
Before:
<PERSON>
<NAME>ChangeMe</NAME>
<NAME2/>
</PERSON>
IsNull: And, setNodeValue() does nothing to <NAME2>
After:
<PERSON>
<NAME>raj</NAME>
<NAME2/>
</PERSON>
When a node text value is null, how do I update a node text value using dbms_xmldom.setNodeValue()
declare
var XMLType;
buf clob;
l_xmldoc dbms_xmldom.DOMDocument;
l_root dbms_xmldom.DOMNode;
l_node dbms_xmldom.DOMNode;
begin
var := xmltype('<PERSON> <NAME>ChangeMe</NAME> <NAME2></NAME2> </PERSON>');
-- Create DOMDocument handle:
l_xmldoc := dbms_xmldom.newDOMDocument
l_root := dbms_xmldom.makeNode(l_xml
-- before
dbms_xmldom.writetobuffer(
dbms_output.put_line('Befo
dbms_output.put_line(buf);
-- replace name.text
l_node := dbms_xslprocessor.selectSi
if dbms_xmldom.isnull(l_node)
dbms_output.put_line('IsNu
dbms_xmldom.setNodeValue(l
else
-- Manipulate:
dbms_xmldom.setNodeValue(l
end if;
-- replace name2.text... how is this done when the text node is null?
l_node := dbms_xslprocessor.selectSi
if dbms_xmldom.isnull(l_node)
dbms_output.put_line('IsNu
dbms_xmldom.setNodeValue(l
else
-- Manipulate:
dbms_xmldom.setNodeValue(l
end if;
-- after
dbms_xmldom.writetobuffer(
dbms_output.put_line('Afte
dbms_output.put_line(buf);
end;
the code above yields the following output:
Before:
<PERSON>
<NAME>ChangeMe</NAME>
<NAME2/>
</PERSON>
IsNull: And, setNodeValue() does nothing to <NAME2>
After:
<PERSON>
<NAME>raj</NAME>
<NAME2/>
</PERSON>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
--> And, 9.2.0.2 is not downloadable from Oracle without a support agreement.
You can download 9.2.0.2 on XP at the following link (or Linux at 9.2.0.4), however, luckily all of our systems will be upgraded to 9.2.0.5 soon anyway!
http://www.oracle.com/technology/software/products/oracle9i/index.html
Thanks
You can download 9.2.0.2 on XP at the following link (or Linux at 9.2.0.4), however, luckily all of our systems will be upgraded to 9.2.0.5 soon anyway!
http://www.oracle.com/technology/software/products/oracle9i/index.html
Thanks
ASKER
I should have said 9.2.0.2 is not available for Windows 2000. Thanks.
ASKER
By the way, I had many problems with 9.2.0.1 and XML. Apparently, some of the XML DB features are only available with 9.2.0.2 and above. And, 9.2.0.2 is not downloadable from Oracle without a support agreement.