DBE_XMLDOM
Interface Description
The advanced function package DBE_XMLDOM is used to access XMLType objects and implement Document Object Model (DOM), which is an interface used to access HTML and XML documents. For details about all types supported by the advanced function package DBE_XMLDOM, see Table 1. For details about all interfaces supported by DBE_XMLDOM, see Table 2.
When the character set of the database is set to SQL_ASCII and the DBE_XMLDOM advanced package is used, an error message is displayed if the input characters exceed the ASCII range.
Type |
Description |
---|---|
DOMATTR |
Implements the DOMAttributes interface. |
DOMDOCUMENT |
Implements the DOMDocument interface. |
DOMELEMENT |
Implements the DOMElement interface. |
DOMNAMEDNODEMAP |
Implements the DOMNamedNodeMap interface. |
DOMNODELIST |
Implements the DOMNodeList interface. |
DOMNODE |
Implements the DOMNode interface. |
DOMTEXT |
Implements the DOMText interface. |
Interface |
Description |
---|---|
Adds the newchild node to the end of the parent(n) node and returns the newly added node. |
|
Creates a DOMElement object with the specified name. |
|
Creates a DOMText node. |
|
Frees resources related to DOMDocument nodes. |
|
Frees resources related to DOMElement nodes. |
|
Frees resources related to DOMNode nodes. |
|
Frees resources related to DOMNodeList nodes. |
|
Returns the attribute values of a DOMElement object by name. |
|
Returns the attribute values of a DOMNode node as a map. |
|
Converts several subnodes under a node into a node list. |
|
Returns the subnodes of a DOMElement node by name. |
|
Returns the first subnode of the specified document. |
|
Returns the first subnode. |
|
Returns the last subnode. |
|
Obtains the number of subnodes under a specified node. |
|
Returns the local name of a node. |
|
Returns the node specified by name. |
|
Returns the next node of the specified node. |
|
Returns the name of a node. |
|
Returns the type of a node. |
|
Obtains the value of a node, depending on its type. |
|
Returns the parent node of a node. |
|
Returns the tag name of the specified DOMElement node. |
|
Checks whether the DOMNode object has any subnode. |
|
Copies a node and specifies the document to which the node belongs. |
|
Checks whether a node is null. |
|
Returns the item corresponding to the index parameter in the mapping. |
|
Converts a DOMNode object to the DOMElement type. |
|
Forcibly converts a node to the DOMNode type. |
|
Returns a new DOMDocument object. |
|
Sets the value of the DOMElement attribute by name. |
|
Sets the character set for a DOMDocument object. |
|
Sets the external DTD of a DOMDocument object. |
|
Sets the value of a node in the DOMNode object. |
|
Writes an XML node to a specified buffer. |
|
Writes an XML node to a specified CLOB. |
|
Writes an XML node to a specified file. |
|
Displays the number of DOM trees of all types in the current session. |
|
Displays statistics such as the memory usage and number of nodes of the DOM tree of the document type. |
|
Displays the number of nodes of each type for a specific document variable. |
- DBE_XMLDOM.APPENDCHILD
Adds the newchild node to the end of the parent(n) node and returns the newly added node. The prototype of the DBE_XMLDOM.APPENDCHILD function is as follows:
1 2 3 4
DBE_XMLDOM.APPENDCHILD( n IN DOMNode, newchild IN DOMNode) RETURN DOMNODE;
Table 3 DBE_XMLDOM.APPENDCHILD parameters Parameter
Description
n
Node to be added
newchild
New node added
- The error message "operation not support" is displayed for the APPEND ATTR node under the DOCUMENT node. Database A does not report an error in this scenario, but the mounting fails.
- The error message "operation not support" is displayed for the APPEND ATTR node under the ATTR node. Database A does not report an error in this scenario, but the mounting fails.
- When multiple child nodes of the ATTR type are added to a parent node, the child nodes with the same key value cannot exist under the same parent node.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
-- Add a DOMNode node to a specified DOC tree and use DBE_XMLDOM.HASCHILDNODES() to check whether the subnode is successfully added. DECLARE doc DBE_XMLDOM.DOMDocument; doc1 DBE_XMLDOM.DOMDocument; root DBE_XMLDOM.DOMElement; rootnode DBE_XMLDOM.DOMNode; child1 DBE_XMLDOM.DOMElement; child2 DBE_XMLDOM.DOMElement; attr DBE_XMLDOM.DOMAttr; text DBE_XMLDOM.DOMTEXT; node DBE_XMLDOM.DOMNode; child1_node DBE_XMLDOM.DOMNode; attr_node DBE_XMLDOM.DOMNode; parent DBE_XMLDOM.DOMNode; buf varchar2(1000); BEGIN doc := DBE_XMLDOM.newDOMDocument(); root := DBE_XMLDOM.createElement(doc, 'root'); rootnode := DBE_xmldom.makeNode(root); node := DBE_XMLDOM.appendChild(DBE_xmldom.makeNode(doc), rootnode); child1 := DBE_XMLDOM.createElement(doc, 'child1'); child1_node := DBE_XMLDOM.makeNode(child1); node := DBE_XMLDOM.appendChild(rootnode, child1_node); attr := DBE_XMLDOM.createAttribute(doc, 'abc'); attr_node := DBE_XMLDOM.makeNode(attr); node := DBE_XMLDOM.appendChild(child1_node, attr_node); IF DBE_XMLDOM.HASCHILDNODES(child1_node) THEN DBE_OUTPUT.print_line('HAS CHILD NODES'); ELSE DBE_OUTPUT.print_line('NOT HAS CHILD NODES '); END IF; parent := DBE_XMLDOM.GETPARENTNODE(attr_node); buf := DBE_XMLDOM.GETNODENAME(parent); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.CREATEELEMENT
Returns the DOMElement object with the specified name. The prototype of the DBE_XMLDOM.CREATEELEMENT function is as follows:
DBE_XMLDOM.CREATEELEMENT( doc IN DOMDOCUMENT, tagName IN VARCHAR2) RETURN DOMELEMENT;
Returns the DOMElement object with the specified name and namespace. The prototype of the DBE_XMLDOM.CREATEELEMENT function is as follows:
DBE_XMLDOM.CREATEELEMENT( doc IN DOMDOCUMENT, tagName IN VARCHAR2, ns IN VARCHAR2) RETURN DOMELEMENT;
Table 4 DBE_XMLDOM.CREATEELEMENT parameters Parameter
Description
doc
Specified DOMDocument object
tagName
Name of the new DOMElement object
ns
Namespace
- When the tagName parameter is set to null or an empty character string, the exception "NULL or invalid TagName argument specified" is thrown.
- The default maximum length of tagName and ns is 32767. If the length exceeds 32767, an exception is thrown.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
-- 1. Create a DOMElement object with the specified name. DECLARE doc dbe_xmldom.domdocument; attr DBE_XMLDOM.DOMATTR; elem DBE_XMLDOM.DOMELEMENT; ans DBE_XMLDOM.DOMATTR; buf varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0" encoding="UTF-8"?> <computer size="ITX"><cpu>Ryzen 9 3950X</cpu> <ram>32GBx2 DDR4 3200MHz</ram> <motherboard>ROG X570i</motherboard> <gpu>RTX2070 Super</gpu> <ssd>1TB NVMe Toshiba + 2TB NVMe WD Black</ssd> <hdd>12TB WD Digital</hdd> <psu>CORSAIR SF750</psu> <case>LIANLI TU150</case> </computer>'); elem := dbe_xmldom.createelement(doc,'elem'); DBE_XMLDOM.WRITETOBUFFER(dbe_xmldom.makenode(elem), buf); DBE_OUTPUT.print_line(buf); END; / -- 2. Create a DOMElement object with the specified name and namespace. DECLARE doc dbe_xmldom.domdocument; attr DBE_XMLDOM.DOMATTR; elem DBE_XMLDOM.DOMELEMENT; ans DBE_XMLDOM.DOMNODE; buf varchar2(1010); list DBE_XMLDOM.DOMNODELIST; node DBE_XMLDOM.DOMNODE; BEGIN doc := dbe_xmldom.newdomdocument('<h:data xmlns:h="http://www.w3.org/TR/html4/"> <h:da1 len="10">test namespace</h:da1><h:da1>bbbbbbbbbb</h:da1></h:data>'); elem := dbe_xmldom.createelement(doc,'elem','http://www.w3.org/TR/html5/'); ans := DBE_XMLDOM.APPENDCHILD(dbe_xmldom.makenode(doc), dbe_xmldom.makenode(elem)); DBE_XMLDOM.WRITETOBUFFER(doc, buf); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.CREATETEXTNODE
Creates and returns a DOMText object. The prototype of the DBE_XMLDOM.CREATETEXTNOD function is as follows:
DBE_XMLDOM.CREATETEXTNODE( doc IN DOMDocument, data IN VARCHAR2) RETURN DOMTEXT;
Table 5 DBE_XMLDOM.CREATETEXTNODE parameters Parameter
Description
doc
Specified DOMDocument object
data
Content of the DOMText node
1. You can enter an empty string or null value for data.
2. The default maximum length of data is 32767. If the length exceeds 32767, an exception is thrown.
- DBE_XMLDOM.FREEDOCUMENT
Frees a DOMDocument node. The prototype of the DBE_XMLDOM.FREEDOCUMENT function is as follows:
DBE_XMLDOM.FREEDOCUMENT( doc IN DOMDOCUMENT);
Table 6 DBE_XMLDOM.FREEDOCUMENT parameters Parameter
Description
doc
Specified DOMDocument node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-- Free the entire DOC tree after the DOMNode node is added to the DOC tree. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; doc_node dbe_xmldom.DOMNODE; root_elmt dbe_xmldom.DOMELEMENT; root_node dbe_xmldom.DOMNODE; value varchar(1000); BEGIN doc := dbe_xmldom.newdomdocument(); doc_node := dbe_xmldom.MAKENODE(doc); root_elmt := dbe_xmldom.CREATEELEMENT(doc,'staff'); root_node:=dbe_xmldom.APPENDCHILD(doc_node, dbe_xmldom.MAKENODE(root_elmt)); dbe_xmldom.freedocument(doc); END; /
- DBE_XMLDOM.FREEELEMENT
Frees a DOMElement node. The prototype of the DBE_XMLDOM.FREEELEMENT function is as follows:
DBE_XMLDOM.FREEELEMENT( elem IN DOMELEMENT);
Table 7 DBE_XMLDOM.FREEELEMENT parameters Parameter
Description
elem
Specified DOMElement node
- DBE_XMLDOM.FREENODE
Frees a DOMNode node. The prototype of the DBE_XMLDOM.FREENODE function is as follows:
DBE_XMLDOM.FREENODE( n IN DOMNODE);
Table 8 DBE_XMLDOM.FREENODE parameters Parameter
Description
n
Specified DOMNode node
- After GaussDB performs the FREENODE operation, the freed node is not available again. After the database A performs the FREENODE operation, the freed node is available again and becomes another node.
- When other interfaces call the freed DOMNode node, the calling is different from that in database A.
- DBE_XMLDOM.FREENODELIST
Frees a DOMNodeList node. The prototype of the DBE_XMLDOM.FREENODE function is as follows:
DBE_XMLDOM.GETLENGTH( nl IN DOMNODELIST);
Table 9 DBE_XMLDOM.FREENODELIST parameters Parameter
Description
nl
Specified DOMNodeList node
- A DOMNodeList node will be completed freed by FREENODELIST.
- When other interfaces call the freed DOMNodelist node, the calling is different from that in database A.
- The input parameter freenodelist cannot be empty.
- DBE_XMLDOM.GETATTRIBUTE
Returns the attribute values of a DOMElement object by name. The prototype of the DBE_XMLDOM.GETATTRIBUTE function is as follows:
DBE_XMLDOM.GETATTRIBUTE( elem IN DOMELEMENT, name IN VARCHAR2) RETURN VARCHAR2;
Returns the attribute values of a DOMElement object by name and namespace URI. The prototype of the DBE_XMLDOM.GETATTRIBUTE function is as follows:DBE_XMLDOM.GETATTRIBUTE( elem IN DOMELEMENT, name IN VARCHAR2, ns IN VARCHAR2) RETURN VARCHAR2;
Table 10 DBE_XMLDOM.GETATTRIBUTE parameters Parameter
Description
elem
Specified DOMElement node
name
Attribute name
ns
Namespace
- The ns parameter of the DBE_XMLDOM.GETATTRIBUTE interface does not support the asterisk (*) parameter.
- GaussDB does not support the namespace prefix as an attribute, and the value of the prefix cannot be queried through the DBE_XMLDOM.GETATTRIBUTE interface.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
-- 1. Return the attribute values of a DOMElement object by name. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar2(1000); BEGIN doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); value := DBE_XMLDOM.getattribute(elem, 'len'); dbe_output.print_line('value: '); dbe_output.print_line(value); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; / -- 2. Return the attribute values of a DOMElement object by name and namespace URI. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar(1000); BEGIN doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm', 'www.huawei.com'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); value := DBE_XMLDOM.getattribute(elem, 'len', 'www.huawei.com'); dbe_output.print_line('value: '); dbe_output.print_line(value); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; /
- DBE_XMLDOM.GETATTRIBUTES
Returns the attribute values of a DOMNode node as a map. The prototype of the DBE_XMLDOM.GETATTRIBUTES function is as follows:
DBE_XMLDOM.GETATTRIBUTES( n IN DOMNode) RETURN DOMNAMEDNODEMAP;
Table 11 DBE_XMLDOM.GETATTRIBUTES parameters Parameter
Description
n
Specified DOMNode node
- DBE_XMLDOM.GETCHILDNODES
Converts several subnodes under a node into a node list. The prototype of the DBE_XMLDOM.GETCHILDNODES function is as follows:
DBE_XMLDOM.GETCHILDNODES( n IN DOMNode) RETURN DOMNodeList;
Table 12 DBE_XMLDOM.GETCHILDNODES parameters Parameter
Description
n
Specified DOMNode node
- DBE_XMLDOM.GETCHILDRENBYTAGNAME
Returns the subnodes of a DOMElement node by name. The prototype of the DBE_XMLDOM.GETCHILDRENBYTAGNAME function is as follows:
DBE_XMLDOM.GETCHILDRENBYTAGNAME ( elem IN DOMELEMENT, name IN VARCHAR2) RETURN DOMNODELIST;
Returns the subnodes of a DOMElement node by name and namespace. The prototype of the DBE_XMLDOM.GETCHILDRENBYTAGNAME function is as follows:DBE_XMLDOM.GETCHILDRENBYTAGNAME ( elem IN DOMELEMENT, name IN VARCHAR2, ns IN VARCHAR2) RETURN DOMNODELIST;
Table 13 DBE_XMLDOM.GETCHILDRENBYTAGNAME parameters Parameter
Description
elem
Specified DOMElement node
name
Attribute name
ns
Namespace
The ns parameter of the DBE_XMLDOM.GETCHILDRENBYTAGNAME interface does not support the asterisk (*) parameter. To obtain all attributes of a node, use the DBE_XMLDOM.GETCHILDNODES interface.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
-- 1. Return the subnodes of a DOMElement node by name. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnodelist dbe_xmldom.domnodelist; node_elem dbe_xmldom.domelement; node dbe_xmldom.domnode; buffer varchar2(1010); value varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0" encoding="UTF-8"?> <students age="16" hight="176"> <student> <name>Jerry</name><age>519</age><sex>man</sex><abc>12345</abc> </student> <student> <name>Bob</name><age>245</age><sex>woman</sex><abc>54321</abc> </student> </students>'); elem := dbe_xmldom.GETDOCUMENTELEMENT(doc); docnodelist := dbe_xmldom.GETCHILDRENBYTAGNAME(elem, 'student'); node := dbe_xmldom.ITEM(docnodelist, 0); node_elem := dbe_xmldom.makeelement(node); value := DBE_XMLDOM.gettagname(node_elem); dbe_output.print_line('value: '); dbe_output.print_line(value); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; /
- DBE_XMLDOM.GETDOCUMENTELEMENT
Returns the first subnode of the specified document. The prototype of the DBE_XMLDOM.GETDOCUMENTELEMENT function is as follows:
DBE_XMLDOM.GETDOCUMENTELEMENT( doc IN DOMDOCUMENT) RETURN DOMELEMENT;
Table 14 DBE_XMLDOM.GETDOCUMENTELEMENT parameters Parameter
Description
doc
Specified DOMDocument node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
-- Obtain the first subnode in the DOC tree and output the node name. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; doc_node dbe_xmldom.DOMNODE; root_elmt dbe_xmldom.DOMELEMENT; root_node dbe_xmldom.DOMNODE; value varchar(1000); BEGIN doc := dbe_xmldom.newdomdocument(); doc_node := dbe_xmldom.MAKENODE(doc); root_elmt := dbe_xmldom.CREATEELEMENT(doc,'staff'); root_node:=dbe_xmldom.APPENDCHILD(doc_node, dbe_xmldom.MAKENODE(root_elmt)); elem := dbe_xmldom.GETDOCUMENTELEMENT(doc); value := DBE_XMLDOM.gettagname(elem); dbe_output.print_line(value); END; /
- DBE_XMLDOM.GETFIRSTCHILD
Returns the first subnode of a node. The prototype of the DBE_XMLDOM.GETFIRSTCHILD function is as follows:
DBE_XMLDOM.GETFIRSTCHILD( n IN DOMNODE) RETURN DOMNODE;
Table 15 DBE_XMLDOM.GETFIRSTCHILD parameters Parameter
Description
n
Specified DOMNode node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-- Obtain the name and type of the first subnode after the DOC tree is converted to the DOMNode type, and then obtain the name of the first subnode of the obtained first DOMNode node. DECLARE doc dbe_xmldom.domdocument; doc_node dbe_xmldom.domnode; root_node dbe_xmldom.domnode; inside_node dbe_xmldom.domnode; node_name varchar2(1000); node_type integer; BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0" encoding="UTF-8"?> <students age="16" hight="176"> <student1> <name>Jerry</name><age>519</age><sex>man</sex><abc>12345</abc> </student1> <student2> <name>Bob</name><age>245</age><sex>woman</sex><abc>54321</abc> </student2> </students>'); doc_node := DBE_XMLDOM.MAKENODE(doc); root_node := DBE_XMLDOM.GETFIRSTCHILD(doc_node); node_name := DBE_XMLDOM.GETNODENAME(root_node); node_type := DBE_XMLDOM.GETNODETYPE(root_node); dbe_output.print_line(node_name); dbe_output.print_line(node_type); inside_node := DBE_XMLDOM.GETFIRSTCHILD(root_node); node_name := DBE_XMLDOM.GETNODENAME(inside_node); dbe_output.print_line(node_name); END; /
- DBE_XMLDOM.GETLASTCHILD
Returns the last subnode of a node. The prototype of the DBE_XMLDOM.GETLASTCHILD function is as follows:
DBE_XMLDOM.GETLASTCHILD( n IN DOMNODE) RETURN DOMNODE;
Table 16 DBE_XMLDOM.GETLASTCHILD parameters Parameter
Description
n
Specified DOMNode node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-- Obtain the name and type of the last subnode after the DOC tree is converted to the DOMNode type, and then obtain the name of the last subnode of the obtained last DOMNode node. DECLARE doc dbe_xmldom.domdocument; doc_node dbe_xmldom.domnode; root_node dbe_xmldom.domnode; inside_node dbe_xmldom.domnode; node_name varchar2(1000); node_type integer; BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0" encoding="UTF-8"?> <students age="16" hight="176"> <student1> <name>Jerry</name><age>519</age><sex>man</sex><abc>12345</abc> </student1> <student2> <name>Bob</name><age>245</age><sex>woman</sex><abc>54321</abc> </student2> </students>'); doc_node := DBE_XMLDOM.MAKENODE(doc); root_node := DBE_XMLDOM.GETFIRSTCHILD(doc_node); node_name := DBE_XMLDOM.GETNODENAME(root_node); node_type := DBE_XMLDOM.GETNODETYPE(root_node); dbe_output.print_line(node_name); dbe_output.print_line(node_type); inside_node := DBE_XMLDOM.GETLASTCHILD(root_node); node_name := DBE_XMLDOM.GETNODENAME(inside_node); dbe_output.print_line(node_name); END; /
- DBE_XMLDOM.GETLENGTH
Returns the number of subnodes under a DOMNamedNodeMap node. The prototype of the DBE_XMLDOM.GETLENGTH function is as follows:
DBE_XMLDOM.GETLENGTH( nnm IN DOMNAMEDNODEMAP) RETURN NUMBER;
Returns the number of subnodes under a DOMNodeList node. The prototype of the DBE_XMLDOM.GETLENGTH function is as follows:DBE_XMLDOM.GETLENGTH( nl IN DOMNODELIST) RETURN NUMBER;
Table 17 DBE_XMLDOM.GETLENGTH parameters Parameter
Description
nnm
Specified DOMNamedNodeMap node
nl
Specified DOMNodeList node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
-- 1. Declare a DOMNamedNodeMap parameter in a function. DECLARE doc DBE_XMLDOM.DOMDocument; elem DBE_XMLDOM.DOMElement; map DBE_XMLDOM.DOMNAMEDNODEMAP; node DBE_XMLDOM.DOMNODE; buf varchar2(10000); len INTEGER; BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <bookstore category="web" cover="paperback"> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> </bookstore>'); elem := DBE_XMLDOM.GETDOCUMENTELEMENT(doc); node := DBE_XMLDOM.MAKENODE(elem); map := DBE_XMLDOM.GETATTRIBUTES(node); len := DBE_XMLDOM.GETLENGTH(map); DBE_OUTPUT.print_line(len); END; / -- 2. Declare a NodeList parameter in a function. DECLARE doc dbe_xmldom.domdocument; node dbe_xmldom.domnode; node1 dbe_xmldom.domnode; nodelist DBE_XMLDOM.DOMNODELIST; len INTEGER; buffer1 varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0" encoding="UTF-8"?> <students age="16" hight="176"> <student> <name>Jerry</name><age>519</age><sex>man</sex><abc>12345</abc> </student> <student> <name>Jerry</name><age>519</age><sex>man</sex><abc>12345</abc> </student> </students>'); node := dbe_xmldom.makenode(doc); node := dbe_xmldom.GETFIRSTCHILD(node); nodelist := DBE_XMLDOM.GETCHILDNODES(node); len := DBE_XMLDOM.GETLENGTH(nodelist); RAISE NOTICE 'len : %', len; END; /
- DBE_XMLDOM.GETLOCALNAME
Returns the local name of the given DOMAttr node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:
DBE_XMLDOM.GETLOCALNAME( a IN DOMATTR) RETURN VARCHAR2;
Returns the local name of the given DOMElement node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:DBE_XMLDOM.GETLOCALNAME( elem IN DOMELEMENT) RETURN VARCHAR2;
Returns the local name of the given DOMNode node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:DBE_XMLDOM.GETLOCALNAME( n IN DOMNODE, data OUT VARCHAR2);
Table 18 DBE_XMLDOM.GETLOCALNAME parameters Parameter
Description
a
Specified DOMAttr node
elem
Specified DOMElement node
n
Specified DOMNode node
data
Returned local name
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-- 2. Use the createElement function to generate a DOMElement node and obtain its local name. DECLARE doc DBE_xmldom.domdocument; elem DBE_xmldom.domelement; value varchar2(10000); BEGIN doc := DBE_xmldom.newdomdocument(); elem := DBE_XMLDOM.createELEMENT(doc, 'root'); value := DBE_XMLDOM.getlocalname(elem); DBE_output.print_line('value: '); DBE_output.print_line(value); END; / -- 3. Convert a DOMElement to a DOMNode node and obtain its local name. DECLARE doc DBE_xmldom.domdocument; elem DBE_xmldom.domelement; node DBE_xmldom.domnode; value varchar2(100); buf varchar2(100); BEGIN doc := DBE_xmldom.newdomdocument(); elem := DBE_XMLDOM.createELEMENT(doc, 'root'); node := DBE_xmldom.makenode(elem); DBE_XMLDOM.getlocalname(node, buf); DBE_output.print_line('buf: '); DBE_output.print_line(buf); END; /
- DBE_XMLDOM.GETNAMEDITEM
Returns the node specified by name. The prototype of the DBE_XMLDOM.GETNAMEDITEM function is as follows:
DBE_XMLDOM.GETNAMEDITEM( nnm IN DOMNAMEDNODEMAP, name IN VARCHAR2) RETURN DOMNODE;
Returns the node specified by name and namespace. The prototype of the DBE_XMLDOM.GETNAMEDITEM function is as follows:DBE_XMLDOM.GETNAMEDITEM( nnm IN DOMNAMEDNODEMAP, name IN VARCHAR2, ns IN VARCHAR2) RETURN DOMNODE;
Table 19 DBE_XMLDOM.GETNAMEDITEM parameters Parameter
Description
nnm
Specified DOMNamedNodeMap object
name
Name of the element to be retrieved
ns
Namespace
- The values of name and nnm can be null, but they are required arguments.
- The default maximum length of name and ns is 32767. If the length exceeds 32767, an error is reported.
- The values of name and ns can be of the int type and contain more than 127 bits.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
-- 1. Return the node specified by name. DECLARE doc DBE_XMLDOM.DOMDocument; elem DBE_XMLDOM.DOMElement; map DBE_XMLDOM.DOMNAMEDNODEMAP; node DBE_XMLDOM.DOMNODE; node2 DBE_XMLDOM.DOMNODE; buf varchar2(1000); buf2 varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"> <book category="cooking"><title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author><year>2005</year> <price>30.00</price></book></bookstore>'); elem := DBE_XMLDOM.GETDOCUMENTELEMENT(doc); node := DBE_XMLDOM.MAKENODE(elem); map := DBE_XMLDOM.GETATTRIBUTES(node); node2:= DBE_XMLDOM.GETNAMEDITEM(map,'category'); DBE_XMLDOM.writeToBuffer(node2, buf2); dbe_output.print_line(buf2); END; / -- 2. Return the node specified by name and namespace. DECLARE doc DBE_XMLDOM.DOMDocument; root DBE_XMLDOM.DOMElement; elem DBE_XMLDOM.DOMElement; map DBE_XMLDOM.DOMNAMEDNODEMAP; node DBE_XMLDOM.DOMNODE; buf varchar2(1000); buf2 varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr h:id="10"><h:td >Apples</h:td> <h:td>Bananas</h:td></h:tr></h:table>'); root := DBE_XMLDOM.getDocumentElement(doc); node := DBE_XMLDOM.MAKENODE(root); node := dbe_xmldom.GETFIRSTCHILD(node); map := DBE_XMLDOM.GETATTRIBUTES(node); node := DBE_XMLDOM.GETNAMEDITEM(map,'id','http://www.w3.org/TR/html4/'); DBE_XMLDOM.writeToBuffer(node, buf2); dbe_output.print_line(buf2); END; /
- DBE_XMLDOM.GETNEXTSIBLING
Returns the next node. The prototype of the DBE_XMLDOM.GETNEXTSIBLING function is as follows:
DBE_XMLDOM.GETNEXTSIBLING( n IN DOMNODE) RETURN DOMNODE;
Table 20 DBE_XMLDOM.GETNEXTSIBLING parameters Parameter
Description
n
Specified DOMNode node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
-- Obtain the first subnode after the DOC tree is converted into the DOMNode type, and obtain the name of the first subnode of the obtained first DOMNode node. Then, obtain the name of the next node through DBE_XMLDOM.GETNEXTSIBLING. DECLARE doc dbe_xmldom.domdocument; doc_node dbe_xmldom.domnode; root_node dbe_xmldom.domnode; inside_node dbe_xmldom.domnode; node_name varchar2(1000); node_type integer; BEGIN doc := dbe_xmldom.newdomdocument('<computer size="ITX"> <cpu>Ryzen 9 3950X</cpu> <ram>32GBx2 DDR4 3200MHz</ram> <motherboard>X570i</motherboard> </computer>'); doc_node := DBE_XMLDOM.MAKENODE(doc); root_node := DBE_XMLDOM.GETFIRSTCHILD(doc_node); node_name := DBE_XMLDOM.GETNODENAME(root_node); node_type := DBE_XMLDOM.GETNODETYPE(root_node); dbe_output.print_line(node_name); dbe_output.print_line(node_type); inside_node := DBE_XMLDOM.GETFIRSTCHILD(root_node); node_name := DBE_XMLDOM.GETNODENAME(inside_node); dbe_output.print_line(node_name); inside_node := DBE_XMLDOM.GETNEXTSIBLING(inside_node); node_name := DBE_XMLDOM.GETNODENAME(inside_node); dbe_output.print_line(node_name); END; /
- DBE_XMLDOM.GETNODENAME
Returns the name of a node. The prototype of the DBE_XMLDOM.GETNODENAME function is as follows:
DBE_XMLDOM.GETNODENAME( n IN DOMNODE) RETURN VARCHAR2;
Table 21 DBE_XMLDOM.GETNODENAME parameters Parameter
Description
n
Specified DOMNode node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
-- Obtain the name of the specified DOMNode node from the DOC tree. DECLARE doc DBE_XMLDOM.DOMDocument; root DBE_XMLDOM.DOMElement; root_node DBE_XMLDOM.DOMNode; inside_node DBE_XMLDOM.DOMNode; buf VARCHAR2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"> <book category="cooking"><title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author><year>2005</year> <price>30.00</price></book></bookstore>'); root := DBE_XMLDOM.getDocumentElement(doc); root_node := DBE_XMLDOM.MAKENODE(root); inside_node := DBE_XMLDOM.GETFIRSTCHILD(root_node); buf := DBE_XMLDOM.GETNODENAME(inside_node); dbe_output.print_line(buf); END; /
- DBE_XMLDOM.GETNODETYPE
Returns the type of a node. The prototype of the DBE_XMLDOM.GETNODETYPE function is as follows:
DBE_XMLDOM.GETNODETYPE( n IN DOMNODE) RETURN NUMBER;
Table 22 DBE_XMLDOM.GETNODETYPE parameters Parameter
Description
n
Specified DOMNode node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
-- Obtain the type of the specified DOMNode node from the DOC tree. DECLARE doc DBE_XMLDOM.DOMDocument; doc_node DBE_XMLDOM.DOMNode; num number; buf varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"> <book category="cooking"><title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author><year>2005</year> <price>30.00</price></book></bookstore>'); doc_node := DBE_XMLDOM.makeNode(doc); num := DBE_XMLDOM.GETNODETYPE(doc_node); dbe_output.print_line(num); buf := DBE_XMLDOM.GETNODENAME(doc_node); dbe_output.print_line(buf); END; /
- DBE_XMLDOM.GETNODEVALUE
Returns the value of a DOMNode node. The prototype of the DBE_XMLDOM.GETNODEVALUE function is as follows:
DBE_XMLDOM.GETNODEVALUE( n IN DOMNODE) RETURN VARCHAR2;
Table 23 DBE_XMLDOM.GETNODEVALUE parameters Parameter
Description
n
Specified DOMNode object
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-- Convert a DOMText node to a DOMNode node and obtain the value of the node. DECLARE buf VARCHAR2(1000); doc DBE_XMLDOM.DOMDocument; text DBE_XMLDOM.DOMText; elem2 DBE_XMLDOM.DOMElement; node DBE_XMLDOM.DOMNode; begin doc := DBE_XMLDOM.NEWDOMDOCUMENT(); text := DBE_XMLDOM.createTextNode(doc, 'aaa'); DBE_XMLDOM.SETNODEVALUE(DBE_XMLDOM.makeNode(text), 'ccc'); buf := DBE_XMLDOM.GETNODEVALUE(DBE_XMLDOM.makeNode(text)); DBE_OUTPUT.print_line(buf); end; /
- DBE_XMLDOM.GETPARENTNODE
Returns the parent node of the given DOMNode node. The prototype of the DBE_XMLDOM.GETPARENTNODE function is as follows:
DBE_XMLDOM.GETPARENTNODE( n IN DOMNODE) RETURN DOMNODE;
Table 24 DBE_XMLDOM.GETPARENTNODE parameters Parameter
Description
n
Specified DOMNode object
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
-- Add a node to the DOC tree and obtain the name of its parent node. DECLARE doc DBE_XMLDOM.DOMDocument; doc1 DBE_XMLDOM.DOMDocument; root DBE_XMLDOM.DOMElement; child1 DBE_XMLDOM.DOMElement; child2 DBE_XMLDOM.DOMElement; attr DBE_XMLDOM.DOMAttr; text DBE_XMLDOM.DOMTEXT; node DBE_XMLDOM.DOMNode; parent DBE_XMLDOM.DOMNode; buf varchar2(1000); BEGIN doc := DBE_XMLDOM.newDOMDocument(); root := DBE_XMLDOM.createElement(doc, 'root'); node := DBE_XMLDOM.appendChild(DBE_xmldom.makeNode(doc),DBE_xmldom.makeNode(root)); child1 := DBE_XMLDOM.createElement(doc, 'child1'); node := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(root), DBE_XMLDOM.makeNode(child1)); child2 := DBE_XMLDOM.createElement(doc, 'child2'); node := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(child1), DBE_XMLDOM.makeNode(child2)); parent := DBE_XMLDOM.GETPARENTNODE(DBE_XMLDOM.makeNode(child2)); buf := DBE_XMLDOM.GETNODENAME(parent); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.GETTAGNAME
Returns the tag name of the specified DOMElement node. The prototype of the DBE_XMLDOM.GETTAGNAME function is as follows:
DBE_XMLDOM.GETTAGNAME( elem IN DOMELEMENT) RETURN VARCHAR2;
Table 25 DBE_XMLDOM.GETTAGNAME parameters Parameter
Description
elem
Specified DOMElement node
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-- Obtain the tag name of a DOMElement node. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; buffer varchar2(1010); value varchar(1000); BEGIN doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(DBE_XMLDOM.NEWDOMDOCUMENT(), 'root'); value := DBE_XMLDOM.gettagname(elem); dbe_output.print_line('value: '); dbe_output.print_line(value); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; /
- DBE_XMLDOM.HASCHILDNODES
Checks whether the DOMNode object has any subnode. The prototype of the DBE_XMLDOM.HASCHILDNODES function is as follows:
DBE_XMLDOM.HASCHILDNODES( n IN DOMNODE) RETURN BOOLEAN;
Table 26 DBE_XMLDOM.HASCHILDNODES parameters Parameter
Description
n
Specified DOMNode object
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
-- Create a node named child1, mount it to the DOC tree, and add a node to child1. Then, check whether the child1 node has any subnode. DECLARE doc DBE_XMLDOM.DOMDocument; doc1 DBE_XMLDOM.DOMDocument; root DBE_XMLDOM.DOMElement; child1 DBE_XMLDOM.DOMElement; child2 DBE_XMLDOM.DOMElement; attr DBE_XMLDOM.DOMAttr; text DBE_XMLDOM.DOMTEXT; node DBE_XMLDOM.DOMNode; buf varchar2(1000); BEGIN doc := DBE_XMLDOM.newDOMDocument(); root := DBE_XMLDOM.createElement(doc, 'root'); node := DBE_XMLDOM.appendChild(DBE_xmldom.makeNode(doc),DBE_xmldom.makeNode(root)); child1 := DBE_XMLDOM.createElement(doc, 'child1'); node := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(root), DBE_XMLDOM.makeNode(child1)); child2 := DBE_XMLDOM.createElement(doc, 'child2'); node := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(child1), DBE_XMLDOM.makeNode(child2)); IF DBE_XMLDOM.HASCHILDNODES(DBE_XMLDOM.makeNode(child1)) THEN DBE_OUTPUT.print_line('HAS CHILD NODES'); ELSE DBE_OUTPUT.print_line('NOT HAS CHILD NODES '); END IF; END; /
- DBE_XMLDOM.IMPORTNODE
Copies a node to another node and mounts the copied node to a specified document. If the type of the copied node does not belong to the 12 types specified by constants of XML DOM, an exception indicating that the type is not supported is thrown. The prototype of the DBE_XMLDOM.IMPORTNODE function is as follows:
DBE_XMLDOM.IMPORTNODE( doc IN DOMDOCUMENT, importedNode IN DOMNODE, deep IN BOOLEAN) RETURN DOMNODE;
Table 27 DBE_XMLDOM.IMPORTNODE parameters Parameter
Description
doc
Document to which the node is mounted
importedNode
Node to be imported
deep
Specifies whether to perform recursive import.
- If the value is TRUE, the node and all its subnodes are imported.
- If the value is FALSE, the node itself is imported.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-- Obtain the root2_node node in the DOC2 tree, copy it, and mount it to the DOC tree. DECLARE doc dbe_xmldom.domdocument; doc2 dbe_xmldom.domdocument; doc_node dbe_xmldom.domnode; doc2_node dbe_xmldom.domnode; root_node dbe_xmldom.domnode; root2_node dbe_xmldom.domnode; import_node dbe_xmldom.domnode; result_node dbe_xmldom.domnode; buffer varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"> <book category="cooking"><title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author><year>2005</year> <price>30.00</price></book></bookstore>'); doc2 := dbe_xmldom.newdomdocument('<case>LIANLI TU150</case>'); doc_node := DBE_XMLDOM.MAKENODE(doc); doc2_node := DBE_XMLDOM.MAKENODE(doc2); root_node := DBE_XMLDOM.GETFIRSTCHILD(doc_node); root2_node := DBE_XMLDOM.GETFIRSTCHILD(doc2_node); DBE_XMLDOM.WRITETOBUFFER(doc, buffer); dbe_output.print_line(buffer); import_node := DBE_XMLDOM.IMPORTNODE(doc, root2_node, TRUE); result_node := DBE_XMLDOM.APPENDCHILD(root_node, import_node); DBE_XMLDOM.WRITETOBUFFER(doc, buffer); dbe_output.print_line(buffer); END; /
- DBE_XMLDOM.ISNULL
Checks whether the given DOMAttr node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:
DBE_XMLDOM.ISNULL( a IN DOMATTR) RETURN BOOLEAN;
Checks whether the given DOMDocument node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( doc IN DOMDOCUMENT) RETURN BOOLEAN;
Checks whether the given DOMElement node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( elem IN DOMELEMENT) RETURN BOOLEAN;
Checks whether the given DOMNamedNodeMap node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( nnm IN DOMNAMEDNODEMAP) RETURN BOOLEAN;
Checks whether the given DOMNode node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( n IN DOMNODE) RETURN BOOLEAN;
Checks whether the given DOMNodeList node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( nl IN DOMNODELIST) RETURN BOOLEAN;
Checks whether the given DOMText node is null. If yes, TRUE is returned. Otherwise, FALSE is returned. The prototype of the DBE_XMLDOM.ISNULL function is as follows:DBE_XMLDOM.ISNULL( t IN DOMTEXT) RETURN BOOLEAN;
Table 28 DBE_XMLDOM.ISNULL parameters Parameter
Description
a
Specified DOMAttr node
doc
Specified DOMDocument node
elem
Specified DOMElement node
nnm
Specified DOMNamedNodeMap node
n
Specified DOMNode node
nl
Specified DOMNodeList node
t
Specified DOMText node
Due to the implementation difference of DBE_XMLDOM.FREEDOCUMENT, an error is reported when the DBE_XMLDOM.ISNULL interface calls the freed DOMDocument node.
Example:1 2 3 4 5 6 7 8 9 10 11 12
--1. Use createAttribute to create a DOMAttr node and check whether the node is empty. -- 2. Declare (but not initialize) a DOMElement node and check whether the node is empty. DECLARE docelem DBE_XMLDOM.DOMElement; BEGIN if DBE_XMLDOM.ISNULL(docelem) then DBE_OUTPUT.print_line('null'); else DBE_OUTPUT.print_line('not null'); end if; END; /
- DBE_XMLDOM.ITEM
Returns the element corresponding to the index in a list based on the index. The prototype of the DBE_XMLDOM.ITEM function is as follows:
DBE_XMLDOM.ITEM( nl IN DOMNODELIST, index IN NUMBER) RETURN DOMNODE;
Returns the element corresponding to the index in a map based on the index. The prototype of the DBE_XMLDOM.ITEM function is as follows:DBE_XMLDOM.ITEM( nnm IN DOMNAMEDNODEMAP, index IN NUMBER) RETURN DOMNODE;
Table 29 DBE_XMLDOM.ITEM parameters Parameter
Description
nl
Specified DOMNodeList object
nnm
Specified DOMNamedNodeMap object
index
Index of the element to be retrieved
For improper input parameters such as Boolean and CLOB, the item function of the map type points to the value of the first index by default.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
-- 1. Return the element corresponding to the index in a map based on the index. DECLARE doc DBE_XMLDOM.DOMDocument; elem DBE_XMLDOM.DOMElement; map DBE_XMLDOM.DOMNAMEDNODEMAP; node DBE_XMLDOM.DOMNODE; node2 DBE_XMLDOM.DOMNODE; buf varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"><book category="cooking"> <title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author> <year>2005</year><price>30.00</price></book></bookstore>'); elem := DBE_XMLDOM.GETDOCUMENTELEMENT(doc); node := DBE_XMLDOM.MAKENODE(elem); map := DBE_XMLDOM.GETATTRIBUTES(DBE_XMLDOM.getFirstChild(node)); node2:= DBE_XMLDOM.item(map,0); DBE_XMLDOM.writeToBuffer(node2, buf); dbe_output.print_line(buf); dbe_xmldom.freedocument(doc); RAISE NOTICE '%', buf; END; / -- 2. Return the element corresponding to the index in a list based on the index. DECLARE doc dbe_xmldom.domdocument; node dbe_xmldom.domnode; node1 dbe_xmldom.domnode; nodelist DBE_XMLDOM.DOMNODELIST; len INTEGER; buffer1 varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<bookstore category="web" cover="paperback"><book category="cooking"> <title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author> <year>2005</year><price>30.00</price></book></bookstore>'); node := dbe_xmldom.makenode(doc); node := dbe_xmldom.GETFIRSTCHILD(node); node := dbe_xmldom.GETFIRSTCHILD(node); nodelist := DBE_XMLDOM.GETCHILDNODES(node); len := DBE_XMLDOM.GETLENGTH(nodelist); RAISE NOTICE 'len : %', len; node1 := DBE_XMLDOM.ITEM(nodelist, 0); IF DBE_XMLDOM.ISNULL(node1) THEN dbe_output.print_line('IS NULL'); ELSE dbe_output.print_line('NOT NULL'); END IF; dbe_xmldom.writetobuffer(node1, buffer1); dbe_output.print_line('buffer1: '); dbe_output.print_line(buffer1); END; /
- DBE_XMLDOM.MAKEELEMENT
Returns the DOMElement object after conversion. The prototype of the DBE_XMLDOM.MAKEELEMENT function is as follows:
DBE_XMLDOM.MAKEELEMENT( n IN DOMNODE) RETURN DOMELEMENT;
Table 30 DBE_XMLDOM.MAKEELEMENT parameters Parameter
Description
n
Specified DOMNode object
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-- Forcibly convert the DOMNode node converted from the DOMElement type back to the DOMElement type. DECLARE buf VARCHAR2(1000); doc DBE_XMLDOM.DOMDocument; elem DBE_XMLDOM.DOMElement; elem2 DBE_XMLDOM.DOMElement; node DBE_XMLDOM.DOMNode; BEGIN doc := DBE_XMLDOM.NEWDOMDOCUMENT(); elem := DBE_XMLDOM.createElement(doc, 'aaa'); node := DBE_XMLDOM.makeNode(elem); elem2 := DBE_XMLDOM.makeElement(node); buf := DBE_XMLDOM.GETNODENAME(DBE_XMLDOM.makeNode(elem2)); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.MAKENODE
Forcibly converts a specified DOMAttr node to a DOMNode node and returns the DOMNode node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:
DBE_XMLDOM.MAKENODE( a IN DOMATTR) RETURN DOMNODE;
Forcibly converts a specified DOMDocument node to a DOMNode node and returns the DOMNode node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:DBE_XMLDOM.MAKENODE( doc IN DOMDOCUMENT) RETURN DOMNODE;
Forcibly converts a specified DOMElement node to a DOMNode node and returns the DOMNode node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:DBE_XMLDOM.MAKENODE( elem IN DOMELEMENT) RETURN DOMNODE;
Forcibly converts a specified DOMText node to a DOMNode node and returns the DOMNode node. The prototype of the DBE_XMLDOM.MAKENODE function is as follows:DBE_XMLDOM.MAKENODE( t IN DOMTEXT) RETURN DOMNODE;
Table 31 DBE_XMLDOM.MAKENODE parameters Parameter
Description
a
Specified DOMAttr node
doc
Specified DOMDocument node
elem
Specified DOMElement node
t
Specified DOMText node
Due to syntax restrictions, when DBE_XMLDOM.MAKENODE is used as the return value of a function, it cannot be directly implemented by running the following command:return DBE_XMLDOM.MAKENODE(doc);
You are advised to run the following command:tmp_node := DBE_XMLDOM.MAKENODE(doc ); return tmp_node;
Example:1 2 3 4 5 6 7 8 9 10 11 12 13
--3. Use newdomdocument to create a parameter of the DOMDocument type. The parameter is not empty and is used as the input parameter of MAKENODE. -- 4. Declare (but not initialize) a DOMText variable, and use it as the input parameter of MAKENODE. DECLARE text DBE_XMLDOM.DOMTEXT; buf VARCHAR2(1000); dom_node DBE_XMLDOM.DOMNODE; BEGIN dom_node := DBE_XMLDOM.makeNode(text); buf := DBE_XMLDOM.GETNODENAME(dom_node); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.NEWDOMDOCUMENT
Returns a new DOMDocument object. The prototype of the DBE_XMLDOM.NEWDOMDOCUMENT function is as follows:
DBE_XMLDOM.NEWDOMDOCUMENT RETURN DOMDOCUMENT;
Returns a new DOMDocument instance object created from the specified XMLType type. The prototype of the DBE_XMLDOM.NEWDOMDOCUMENT function is as follows:DBE_XMLDOM.NEWDOMDOCUMENT( xmldoc IN SYS.XMLTYPE) RETURN DOMDOCUMENT;
Returns a new DOMDocument instance object created from the specified CLOB type. The prototype of the DBE_XMLDOM.NEWDOMDOCUMENT function is as follows:DBE_XMLDOM.NEWDOMDOCUMENT( cl IN CLOB) RETURN DOMDOCUMENT;
Table 32 DBE_XMLDOM.NEWDOMDOCUMENT parameters Parameter
Description
xmldoc
Specified XMLType type
cl
Specified CLOB type
- The size of the input parameter must be less than 2 GB.
- Currently, external DTD parsing is not supported.
- The document created by NEWDOMDOCUMENT uses the UTF-8 character set by default.
- Each document parsed from the same XMLType instance is independent, and the modification of the document does not affect the XMLType.
- For details about the differences between our database and database A, see DBE_XMLPARSER.PARSECLOB.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
-- 1. Return a new DOMDocument object. DECLARE doc dbe_xmldom.domdocument; buffer varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument(); dbe_xmldom.setdoctype(doc, 'note', 'sysid', 'pubid'); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_xmldom.freedocument(doc); END; / -- 2. Return a new DOMDocument instance object created from the specified CLOB type. DECLARE doc dbe_xmldom.domdocument; buffer varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <note><to>test</to><from>Jani</from><heading>Reminder</heading> <body>Don''t forget me this weekend!</body></note>'); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_xmldom.freedocument(doc); END; / -- 3. Return a new DOMDocument instance object created from the specified XMLType type. DECLARE doc dbe_xmldom.domdocument; xt xmltype; buffer varchar2(1010); BEGIN xt := xmltype('<h:data xmlns:h="http://www.w3.org/TR/html4/"> <h:da1 len="10">test namespace</h:da1> <h:da1>bbbbbbbbbb</h:da1> </h:data>'); doc := dbe_xmldom.newdomdocument(xt); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_xmldom.freedocument(doc); END; /
- DBE_XMLDOM.SETATTRIBUTE
Sets the value of the DOMElement attribute by name. The prototype of the DBE_XMLDOM.SETATTRIBUTE function is as follows:
DBE_XMLDOM.SETATTRIBUTE( elem IN DOMELEMENT, name IN VARCHAR2, value IN VARCHAR2);
Sets the attribute values of a DOMElement object by name and namespace URI. The prototype of the DBE_XMLDOM.SETATTRIBUTE function is as follows:DBE_XMLDOM.SETATTRIBUTE( elem IN DOMELEMENT, name IN VARCHAR2, value IN VARCHAR2, ns IN VARCHAR2);
Table 33 DBE_XMLDOM.SETATTRIBUTE parameters Parameter
Description
elem
Specified DOMElement node
name
Attribute name
value
Attribute value
ns
Namespace
Multiple attributes can be added through the DBE_XMLDOM.SETATTRIBUTE interface. The attribute name cannot be null, and attributes with the same name cannot exist in the same DOMElement node. If you want to add attributes with the same name, you should explicitly set a namespace for each attribute with the same name, but you are advised not to perform such operations. If an attribute exists in a namespace, the specified namespace must be displayed when you modify the attribute. Otherwise, the attribute with the same name is added.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
-- 1. Set the value of the DOMElement attribute by name. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar(1000); BEGIN doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; / -- 2. Set the attribute values of a DOMElement object by name and namespace URI. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar(1000); begin doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm', 'www.huawei.com'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; / -- 3. Change the values of the DOMElement attributes by name. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar(1000); BEGIN doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm'); DBE_XMLDOM.setattribute(elem, 'len', '55cm'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; / -- 4. Change the values of the DOMElement attributes by name and namespace URI. DECLARE doc dbe_xmldom.domdocument; elem dbe_xmldom.domelement; docnode DBE_XMLDOM.DOMNode; buffer varchar2(1010); value varchar(1000); begin doc := dbe_xmldom.newDOMDocument(); elem := DBE_XMLDOM.CREATEELEMENT(doc, 'root'); DBE_XMLDOM.setattribute(elem, 'len', '50cm', 'www.huawei.com'); DBE_XMLDOM.setattribute(elem, 'len', '55cm', 'www.huawei.com'); docnode := DBE_XMLDOM.appendChild(DBE_XMLDOM.makeNode(doc), DBE_XMLDOM.makeNode(elem)); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); END; /
- DBE_XMLDOM.SETCHARSET
Sets the character set for a DOMDocument object. The prototype of the DBE_XMLDOM.SETCHARSET function is as follows:
DBE_XMLDOM.SETCHARSET( doc IN DOMDocument, charset IN VARCHAR2);
Table 34 DBE_XMLDOM.SETCHARSET parameters Parameter
Description
doc
Specified DOMDocument node
charset
Character set
- The value of charset contains a maximum of 60 bytes.
- Currently, the following character sets are supported: UTF-8, UTF-16, UCS-4, UCS-2, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-2022-JP, Shift_JIS, EUC-JP and ASCII. If you enter other character sets, an error is reported or garbled characters may be displayed.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-- Set the UTF-16 character set for the DOC tree and print the DOC tree to the buffer. DECLARE doc dbe_xmldom.domdocument; buffer varchar2(1010); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]> <note><to>test</to><from>Jani</from><heading>Reminder</heading> <body>Don''t forget me this weekend!</body></note>'); dbe_xmldom.setcharset(doc, 'utf-16'); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_xmldom.freedocument(doc); END; /
- DBE_XMLDOM.SETDOCTYPE
Sets the external DTD of a DOMDocument object. The prototype of the DBE_XMLDOM.SETDOCTYPE function is as follows:
DBE_XMLDOM.SETDOCTYPE( doc IN DOMDocument, name IN VARCHAR2, sysid IN VARCHAR2, pubid IN VARCHAR2);
Table 35 DBE_XMLDOM.SETDOCTYPE parameters Parameter
Description
doc
Specified DOMDocument node
name
Name of the DOCType to be initialized
sysid
ID of the system whose DOCType needs to be initialized
pubid
Public ID of the DOCType to be initialized
The total length of name, sysid, and pubid cannot exceed 32500 bytes.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-- After the initial system ID, public ID, and name are set for the external DTD of the DOMDocument, the DOC tree modified each time is output to the buffer. DECLARE doc dbe_xmldom.domdocument; buffer varchar2(1010); begin doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]> <note><to>test</to><from>Jani</from><heading>Reminder</heading> <body>Don''t forget me this weekend!</body></note>'); dbe_xmldom.setdoctype(doc, 'note', 'sysid', 'pubid'); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_output.print_line('------------------------------------------------'); dbe_xmldom.setdoctype(doc, 'n0te', NULL, ''); dbe_xmldom.setdoctype(doc, 'n0t1e', NULL, ''); dbe_xmldom.writetobuffer(doc, buffer); dbe_output.print_line('buffer: '); dbe_output.print_line(buffer); dbe_xmldom.freedocument(doc); END; /
- DBE_XMLDOM.SETNODEVALUE
Sets the value of a node in the DOMNode object. The prototype of the DBE_XMLDOM.SETNODEVALUE function is as follows:
DBE_XMLDOM.SETNODEVALUE( n IN DOMNODE, nodeValue IN VARCHAR2);
Table 36 DBE_XMLDOM.SETNODEVALUE parameters Parameter
Description
n
Specified DOMNode object
nodeValue
String to be set in the DOMNode object
- You can enter an empty string or null value for nodeValue, but the node value will not be changed.
- Currently, nodeValue does not support the escape character '&'. If the character string contains the escape character, the node value will be cleared.
- The default maximum length of nodeValue is restricted by the VARCHAR2 type and is 32767 bytes. If the length exceeds 32767 bytes, an exception is thrown.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-- After setting a node value different from the initial value for the DOMNode node that is converted from DOMText, obtain and output the node value. DECLARE buf VARCHAR2(1000); doc DBE_XMLDOM.DOMDocument; text DBE_XMLDOM.DOMText; elem2 DBE_XMLDOM.DOMElement; node DBE_XMLDOM.DOMNode; BEGIN doc := DBE_XMLDOM.NEWDOMDOCUMENT(); text := DBE_XMLDOM.createTextNode(doc, 'aaa'); DBE_XMLDOM.SETNODEVALUE(DBE_XMLDOM.makeNode(text), 'ccc'); buf := DBE_XMLDOM.GETNODEVALUE(DBE_XMLDOM.makeNode(text)); DBE_OUTPUT.print_line(buf); END; /
- DBE_XMLDOM.WRITETOBUFFER
Writes an XML node to a specified buffer using the database character set. The prototype of the DBE_XMLDOM.WRITETOBUFFER function is as follows:
DBE_XMLDOM.WRITETOBUFFER( doc IN DOMDOCUMENT, buffer INOUT VARCHAR2);
Writes an XML document to a specified buffer using the database character set. The prototype of the DBE_XMLDOM.WRITETOBUFFER function is as follows:DBE_XMLDOM.WRITETOBUFFER( n IN DOMNODE, buffer INOUT VARCHAR2);
Table 37 DBE_XMLDOM.WRITETOBUFFER parameters Parameter
Description
doc
Specified DOMDocument node
buffer
Buffer for the write operation
n
Specified DOMNode node
- The buffer to which the writetobuffer function writes is less than 1 GB.
- This function adds content such as indentation to format the output. The output document will contain the XML declaration version and encoding.
- By default, XML files are output in the UTF-8 character set.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-- 1. Enter a parameter of the DOMNode type. DECLARE doc dbe_xmldom.domdocument; elem DBE_XMLDOM.DOMELEMENT; buf varchar2(1000); BEGIN doc := dbe_xmldom.newdomdocument(); elem := dbe_xmldom.createelement(doc,'elem'); DBE_XMLDOM.WRITETOBUFFER(dbe_xmldom.makenode(elem), buf); DBE_OUTPUT.print_line(buf); END; / -- 2. Enter a parameter of the DOMDocument type. DECLARE doc DBE_XMLDOM.DOMDocument; buf VARCHAR2(1000); BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]> <note><to>test</to><from>Jani</from><heading>Reminder</heading> <body>Don''t forget me this weekend!</body></note>'); DBE_XMLDOM.WRITETOBUFFER(doc, buf); DBE_OUTPUT.print_line('doc: '); DBE_OUTPUT.print_line(buf); DBE_XMLDOM.FREEDOCUMENT(doc); END; /
- DBE_XMLDOM.WRITETOCLOB
Writes an XML node to a specified CLOB using the database character set. The prototype of the DBE_XMLDOM.WRITETOCLOB function is as follows:
DBE_XMLDOM.WRITETOCLOB( doc IN DOMDOCUMENT, cl INOUT CLOB);
Writes an XML node to a specified CLOB using the database character set. The prototype of the DBE_XMLDOM.WRITETOCLOB function is as follows:DBE_XMLDOM.WRITETOCLOB( n IN DOMNODE, cl INOUT CLOB);
Table 38 DBE_XMLDOM.WRITETOCLOB parameters Parameter
Description
doc
Specified DOMDocument node
cl
CLOB to be written
n
Specified DOMNode node
- The doc parameter is an input parameter. The value of writetoclob is less than 2 GB.
- This function adds content such as indentation to format the output. The output document will contain the XML declaration version and encoding.
- By default, XML files are output in the UTF-8 character set.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
-- 1. Enter a parameter of the DOMNode type. DECLARE CL CLOB; N DBE_XMLDOM.DOMNODE; BEGIN DBE_XMLDOM.WRITETOCLOB(N, CL); DBE_OUTPUT.PRINT_LINE(CL); END; / -- 2. Enter a parameter of the DOMDocument type. DECLARE doc dbe_xmldom.domdocument; mclob clob; BEGIN doc := dbe_xmldom.newdomdocument('<?xml version="1.0"?> <!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]> <note><to>test</to><from>Jani</from><heading>Reminder</heading> <body>Don''t forget me this weekend!</body></note>'); dbe_xmldom.writetoclob(doc, mclob); dbe_output.print_line('mclob: '); dbe_output.print_line(mclob); dbe_xmldom.freedocument(doc); END; /
- DBE_XMLDOM.WRITETOFILE
Writes an XML node to a specified file using the database character set. The prototype of the DBE_XMLDOM.WRITETOFILE function is as follows:
DBE_XMLDOM.WRITETOCLOB( doc IN DOMDOCUMENT, fileName IN VARCHAR2);
Writes an XML node to a specified file using the database character set. The prototype of the DBE_XMLDOM.WRITETOFILE function is as follows:DBE_XMLDOM.WRITETOCLOB( n IN DOMNODE, fileName IN VARCHAR2);
Writes an XML document to a specified file using the specified character set. The prototype of the DBE_XMLDOM.WRITETOFILE function is as follows:DBE_XMLDOM.WRITETOCLOB( doc IN DOMDOCUMENT, fileName IN VARCHAR2, charset IN VARCHAR2);
Writes an XML document to a specified file using the specified character set. The prototype of the DBE_XMLDOM.WRITETOFILE function is as follows:DBE_XMLDOM.WRITETOCLOB( n IN DOMNODE, fileName IN VARCHAR2, charset IN VARCHAR2);
Table 39 DBE_XMLDOM.WRITETOFILE parameters Parameter
Description
doc
Specified DOMDocument node
fileName
File to be written
n
Specified DOMNode node
charset
Specified character set
- The doc parameter is an input parameter. The value of filename can contain a maximum of 255 bytes, and the value of charset can contain a maximum of 60 bytes. For details about the character sets supported by charset, see the DBE_XMLDOM.SETCHARSET interface.
- This function adds content such as indentation to format the output. The output document will contain the XML declaration version and encoding.
- If newdomdocument() is used to create a document without parameters, no error is reported when charset is not specified. The UTF-8 character set is used by default.
- The filename must be in the path created in pg_directory. The backslash (\) in the filename will be converted to a slash (/). Only one slash (/) is allowed. The file name must be in the pg_directory_name/file_name.xml format. The output file must be in the XML format.
- When the GUC parameter safe_data_path is enabled, you can only use the advanced package to read and write files in the file path specified by safe_data_path.
- Before creating a directory, ensure that the directory exists in the operating system and the user has the read and write permissions on the directory. For details about how to create a directory, see CREATE DIRECTORY.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
-- Before creating a directory, ensure that the directory exists in the operating system and the user has the read and write permissions on the directory. create directory dir as '/tmp'; -- 1. Write an XML node to a specified file using the database character set. DECLARE FPATH VARCHAR2(1000); DOC DBE_XMLDOM.DOMDOCUMENT; BEGIN DOC := DBE_XMLDOM.NEWDOMDOCUMENT('<ROOT> <A ATTR1="A_VALUE"> <ACHILD>ACHILD TXT</ACHILD> </A> <B>B TXT</B> <C/> </ROOT>'); FPATH := 'dir/simplexml.xml'; DBE_XMLDOM.WRITETOFILE(DOC, FPATH); END; / -- 2. Write an XML document to a specified file using the specified character set. DECLARE SRC VARCHAR(1000); FPATH VARCHAR2(1000); DOC DBE_XMLDOM.DOMDOCUMENT; ELE DBE_XMLDOM.DOMELEMENT; BEGIN FPATH := 'dir/simplexml.xml'; SRC := '<ROOT> <A ATTR1="A_VALUE"> <ACHILD>ACHILD TXT</ACHILD> </A> <B>B TXT</B> <C/> </ROOT>'; DOC := DBE_XMLDOM.NEWDOMDOCUMENT(SRC); ELE := DBE_XMLDOM.GETDOCUMENTELEMENT(DOC); DBE_XMLDOM.WRITETOFILE(DBE_XMLDOM.MAKENODE(ELE), FPATH, 'ASCII'); DBE_XMLDOM.FREEDOCUMENT(DOC); END; / drop directory dir;
- DBE_XMLDOM.GETSESSIONTREENUM
Queries the number of DOM trees of all types in the current session. The prototype of the DBE_XMLDOM.GETSESSIONTREENUM function is as follows:
DBE_XMLDOM.GETSESSIONTREENUM() RETURN INTEGER;
For DOM trees that have used FREEElement and FREENode, this function still counts them.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
-- Create three documents and obtain the number of DOM trees in the current session. DECLARE doc DBE_XMLDOM.DOMDocument; doc2 DBE_XMLDOM.DOMDocument; doc3 DBE_XMLDOM.DOMDocument; buffer varchar2(1010); BEGIN -- Create three documents. doc := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <root> <elem1 attr="attrtest"> <elem2>Im text</elem2> <elem3>Im text too</elem3> </elem1> <elem4>Text</elem4> </root> '); doc2 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <computer size="ITX" price="19999"> <cpu>Ryzen 9 3950X</cpu> <ram>32GBx2 DDR4 3200MHz</ram> <motherboard>ROG X570i</motherboard> <gpu>RTX2070 Super</gpu> <ssd>1TB NVMe Toshiba + 2TB NVMe WD Black</ssd> <hdd>12TB WD Digital</hdd> <psu>CORSAIR SF750</psu> <case>LIANLI TU150</case> </computer> '); doc3 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <bookstore> <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore> '); -- Print IDs. DBE_OUTPUT.PRINT_LINE(doc.id); DBE_OUTPUT.PRINT_LINE(doc2.id); DBE_OUTPUT.PRINT_LINE(doc3.id); -- Call functions and print them. DBE_OUTPUT.PRINT_LINE(DBE_XMLDOM.GETSESSIONTREENUM()); -- Release the documents. DBE_XMLDOM.FREEDOCUMENT(doc); DBE_XMLDOM.FREEDOCUMENT(doc2); DBE_XMLDOM.FREEDOCUMENT(doc3); END; /
- DBE_XMLDOM.GETDOCTREESINFO
Queries the DOM tree information of the document type in the current session, such as the memory usage. The prototype of the DBE_XMLDOM.GETDOCTREESINFO function is as follows:
DBE_XMLDOM.GETDOCTREESINFO() RETURN VARCHAR2;
This function collects statistics only on DOM tree nodes of the document type.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
-- Create three documents and obtain the information about the document tree in the current session. DECLARE doc DBE_XMLDOM.DOMDocument; doc2 DBE_XMLDOM.DOMDocument; doc3 DBE_XMLDOM.DOMDocument; buffer varchar2(1010); BEGIN -- Create three documents. doc := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <root> <elem1 attr="attrtest"> <elem2>Im text</elem2> <elem3>Im text too</elem3> </elem1> <elem4>Text</elem4> </root> '); doc2 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <computer size="ITX" price="19999"> <cpu>Ryzen 9 3950X</cpu> <ram>32GBx2 DDR4 3200MHz</ram> <motherboard>ROG X570i</motherboard> <gpu>RTX2070 Super</gpu> <ssd>1TB NVMe Toshiba + 2TB NVMe WD Black</ssd> <hdd>12TB WD Digital</hdd> <psu>CORSAIR SF750</psu> <case>LIANLI TU150</case> </computer> '); doc3 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <bookstore> <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore> '); -- Print IDs. DBE_OUTPUT.PRINT_LINE(doc.id); DBE_OUTPUT.PRINT_LINE(doc2.id); DBE_OUTPUT.PRINT_LINE(doc3.id); -- Call functions and print them. DBE_OUTPUT.PRINT_LINE(DBE_XMLDOM.GETDOCTREESINFO()); -- Release the documents. DBE_XMLDOM.FREEDOCUMENT(doc); DBE_XMLDOM.FREEDOCUMENT(doc2); DBE_XMLDOM.FREEDOCUMENT(doc3); END; /
- DBE_XMLDOM.GETDETAILDOCTREEINFO
Queries the number of subnodes of each type in the transferred document. The prototype of the DBE_XMLDOM.GETDETAILDOCTREEINFO function is as follows:
DBE_XMLDOM.GETDETAILDOCTREEINFO( doc IN DOMDOCUMENT ) RETURN VARCHAR2;
Table 40 DBE_XMLDOM.GETDETAILDOCTREEINFO parameters Parameter
Description
doc
Specified DOMDocument node
This function collects statistics only on DOM tree nodes of the document type.
Example:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
-- Create three documents and use this function to obtain the number of nodes of each type in each document. DECLARE doc DBE_XMLDOM.DOMDocument; doc2 DBE_XMLDOM.DOMDocument; doc3 DBE_XMLDOM.DOMDocument; buffer varchar2(1010); BEGIN -- Create three documents. doc := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <root> <elem1 attr="attrtest"> <elem2>Im text</elem2> <elem3>Im text too</elem3> </elem1> <elem4>Text</elem4> </root> '); doc2 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <computer size="ITX" price="19999"> <cpu>Ryzen 9 3950X</cpu> <ram>32GBx2 DDR4 3200MHz</ram> <motherboard>ROG X570i</motherboard> <gpu>RTX2070 Super</gpu> <ssd>1TB NVMe Toshiba + 2TB NVMe WD Black</ssd> <hdd>12TB WD Digital</hdd> <psu>CORSAIR SF750</psu> <case>LIANLI TU150</case> </computer> '); doc3 := DBE_XMLDOM.NEWDOMDOCUMENT('<?xml version="1.0"?> <bookstore> <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore> '); -- Print IDs. DBE_OUTPUT.PRINT_LINE(doc.id); DBE_OUTPUT.PRINT_LINE(doc2.id); DBE_OUTPUT.PRINT_LINE(doc3.id); -- Call functions and print them. buffer := DBE_XMLDOM.GETDETAILDOCTREEINFO(doc); DBE_OUTPUT.PRINT_LINE(buffer); buffer := DBE_XMLDOM.GETDETAILDOCTREEINFO(doc2); DBE_OUTPUT.PRINT_LINE(buffer); buffer := DBE_XMLDOM.GETDETAILDOCTREEINFO(doc3); DBE_OUTPUT.PRINT_LINE(buffer); -- Release the documents. DBE_XMLDOM.FREEDOCUMENT(doc); DBE_XMLDOM.FREEDOCUMENT(doc2); DBE_XMLDOM.FREEDOCUMENT(doc3); END; /
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot