oracle dom文件,oracle xmldom 在线 帮助 文档

本文通过示例展示了如何使用PL/SQL在内存中创建并操作DOMDocument,实现XML文档的动态修改,然后将更改后的数据持久化到数据库。重点在于演示了DOMDocument的使用和数据的前后变化对比。
摘要由CSDN通过智能技术生成

Example 11-1 Creating and Manipulating a DOM Document

This example creates a hierarchical, in-memory representation of an XML document – a DOM document. It uses a handle to this DOM document to manipulate it: print it, change part of it, and print it again after the change. Manipulating the DOM document by its handle also indirectly affects the XML data represented by the document, so that querying that data after the change shows the changed result.

The in-memory document is created from an XMLType variable using PL/SQL function newDOMDocument . The handle to this document is created using function makeNode . The document is written to a VARCHAR2 buffer using function writeToBuffer , and the buffer is printed using DBMS_OUTPUT.put_line .

After manipulating the document using various DBMS_XMLDOM procedures, the (changed) data in the XMLType variable is inserted into a table and queried, showing the change. It is only when the data is inserted into a database table that it becomes persistent; until then, it exists in memory only. This persistence is demonstrated by the fact that the database query is made after the in-memory document (DOMDocument instance) has been freed.

CREATE TABLE person OF XMLType;

DECLARE

var XMLType;

doc DBMS_XMLDOM.DOMDocument;

ndoc DBMS_XMLDOM.DOMNode;

docelem DBMS_XMLDOM.DOMElement;

node DBMS_XMLDOM.DOMNode;

childnode DBMS_XMLDOM.DOMNode;

nodelist DBMS_XMLDOM.DOMNodelist;

buf VARCHAR2(2000);

BEGIN

var := XMLType('ramesh

');

-- Create DOMDocument handle

doc := DBMS_XMLDOM.newDOMDocument(var);

ndoc := DBMS_XMLDOM.makeNode(doc);

DBMS_XMLDOM.writeToBuffer(ndoc, buf);

DBMS_OUTPUT.put_line('Before:

'||buf);

docelem := DBMS_XMLDOM.getDocumentElement(doc);

-- Access element

nodelist := DBMS_XMLDOM.getElementsByTagName(docelem, 'NAME

');

node := DBMS_XMLDOM.item(nodelist, 0);

childnode := DBMS_XMLDOM.getFirstChild(node);

-- Manipulate element

DBMS_XMLDOM.setNodeValue(childnode, 'raj

');

DBMS_XMLDOM.writeToBuffer(ndoc, buf);

DBMS_OUTPUT.put_line('After:

'||buf);

DBMS_XMLDOM.freeDocument(doc);

INSERT INTO person VALUES (var);

END;

/

This produces the following output:

Before:

ramesh

After:

raj

This query confirms that the data has changed:

SELECT * FROM person;

SYS_NC_ROWINFO$

---------------

raj

1 row selected.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值