Table of Contents
This chapter briefly introduces the DBMS_XMLDOM package, and describes how to use the procedures and functions of the package. DBMS_XMLDOM package is not supported in AIX, Windows, Linux IA64, Solaris x86.
DBMS_XMLDOM provides DOM API for XML document processing.
This section describes the constants defined in the DBMS_XMLDOM package.
ELEMENT_NODE
ELEMENT_NODE CONSTANT PLS_INTEGER := 1;
ATTRIBUTE_NODE
ATTRIBUTE_NODE CONSTANT PLS_INTEGER := 2;
TEXT_NODE
TEXT_NODE CONSTANT PLS_INTEGER := 3;
CDATA_SECTION_NODE
CDATA_SECTION_NODE CONSTANT PLS_INTEGER := 4;
ENTITY_REFERENCE_NODE
ENTITY_REFERENCE_NODE CONSTANT PLS_INTEGER := 5;
ENTITY_NODE
ENTITY_NODE CONSTANT PLS_INTEGER := 6;
PROCESSING_INSTRUCTION_NODE
PROCESSING_INSTRUCTION_NODE CONSTANT PLS_INTEGER := 7;
COMMENT_NODE
COMMENT_NODE CONSTANT PLS_INTEGER := 8;
DOCUMENT_NODE
DOCUMENT_NODE CONSTANT PLS_INTEGER := 9;
DOCUMENT_TYPE_NODE
DOCUMENT_TYPE_NODE CONSTANT PLS_INTEGER := 10;
DOCUMENT_FRAGMENT_NODE
DOCUMENT_FRAGMENT_NODE CONSTANT PLS_INTEGER := 11;
NOTATION_NODE
NOTATION_NODE CONSTANT PLS_INTEGER := 12;
This section describes the types provided by the DBMS_XMLDOM package.
A RECORD type with a RAW type ID. Represents an attribute in the DOM object.
Details about the DOMAttr type are as follows:
Prototype
TYPE DOMAttr IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a CDataSection object.
Details about the DOMCDataSection type are as follows:
Prototype
TYPE DOMCDataSection IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a CharacterData object.
Details about the DOMCharacterData type are as follows:
Prototype
TYPE DOMCharacterData IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a Comment object.
Details about the DOMComment type are as follows:
Prototype
TYPE DOMComment IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a Document object.
Details about the DOMDocument type are as follows:
Prototype
TYPE DOMDocument IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a DocumentFragment object.
Details about the DOMDocumentFragment type are as follows:
Prototype
TYPE DOMDocumentFragment IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a DocumentType object.
Details about the DOMDocumentType type are as follows:
Prototype
TYPE DOMDocumentType IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents an element object.
Details about the DOMElement type are as follows:
Prototype
TYPE DOMElement IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents an Entity object.
Details about the DOMEntity type are as follows:
Prototype
TYPE DOMEntity IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents an EntityReference object.
Details about the DOMEntityReference type are as follows:
Prototype
TYPE DOMEntityReference IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents an Implementation object.
Details about the DOMImplementation type are as follows:
Prototype
TYPE DOMImplementation IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a NamedNodeMap object.
Details about the DOMNamedNodeMap type are as follows:
Prototype
TYPE DOMNamedNodeMap IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a Node object.
Details about the DOMNode type are as follows:
Prototype
TYPE DOMNode IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a NodeList object.
Details about the DOMNodeList type are as follows:
Prototype
TYPE DOMNodeList IS RECORD(id RAW(16));
A RECORD type with a RAW type ID. Represents a Notation object.
Details about the DOMNotation type are as follows:
Prototype
TYPE DOMNotation IS RECORD(id RAW(16));
This section describes the procedures and functions provided by the DBMS_XMLDOM package, in alphabetical order.
Adds the selected node to the Document, and deletes the node from the previous document it belonged to.
Details about the ADOPTNODE function are as follows:
Prototype
DBMS_XMLDOM.ADOPTNODE ( doc IN DOMDocument, importedNode IN DOMNode ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
doc | Document to add the node to. |
importedNode | Node to add to the Document. |
Example
declare doc dbms_xmldom.DOMDocument; new_doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; n_ele dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; new_doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); n_ele := dbms_xmldom.makeNode(ele); n := dbms_xmldom.appendChild(root, n_ele); n := dbms_xmldom.adoptNode(new_doc, n_ele); end; /
Adds a child node to the specified node and outputs the new child node.
Details about the APPENDCHILD function are as follows:
Prototype
DBMS_XMLDOM.APPENDCHILD ( n IN DOMNode, newchild IN DOMNode ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
n | Node to add the child node to. |
newchild | New child node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); n := dbms_xmldom.makeNode(ele); n := dbms_xmldom.appendChild(root, n); end; /
Creates a CDataSection in the specified document.
Details about the CREATECDATASECTION function are as follows:
Parameters
Parameter | Description |
---|---|
doc | Document to create a CDataSection for. |
data | Content for CDataSection. |
Example
declare doc dbms_xmldom.DOMDocument; cd dbms_xmldom.DOMCDataSection; begin doc := dbms_xmldom.newDomDocument; cd := dbms_xmldom.createCDataSection(doc, 'contents of cdatasection'); end; /
Creates a COMMENT in the specified document.
Details about the CREATECOMMENT function are as follows:
Prototype
DBMS_XMLDOM.CREATECOMMENT ( doc IN DOMDocument, data IN VARCHAR2 ) RETURN DOMComment;
Parameters
Parameter | Description |
---|---|
doc | Document to create a COMMENT for. |
data | Content for COMMENT. |
Example
declare doc dbms_xmldom.DOMDocument; cm dbms_xmldom.DOMComment; begin doc := dbms_xmldom.newDomDocument; cm := dbms_xmldom.createComment(doc, 'comment!!'); end; /
Creates an element in the specified document.
Details about the CREATEELEMENT function are as follows:
Prototype
DBMS_XMLDOM.CREATEELEMENT ( doc IN DOMDocument, tagname IN VARCHAR2 ) RETURN DOMElement;
Parameters
Parameter | Description |
---|---|
doc | Document to create an element for. |
tagname | Tagname of the Element. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); end; /
Creates a Text node in the specified document.
Details about the CREATETEXTNODE function are as follows:
Prototype
DBMS_XMLDOM.CREATETEXTNODE ( doc IN DOMDocument, data IN VARCHAR2 ) RETURN DOMText;
Parameters
Parameter | Description |
---|---|
doc | Document to create a Text node for. |
data | Text content. |
Example
declare doc dbms_xmldom.DOMDocument; txt dbms_xmldom.DOMText; begin doc := dbms_xmldom.newDomDocument; txt := dbms_xmldom.createTextNode(doc, 'text'); end; /
Initializes the specified DOMDocumentFragment object.
Details about the FREEDOCFRAG procedure are as follows:
Prototype
DBMS_XMLDOM.FREEDOCFRAG ( doc IN DOMDocumentFragment );
Parameter
Parameter | Description |
---|---|
df | DocumentFragment to initialize. |
Frees resources associated with the specified Document.
Details about the FREEDOCUMENT procedure are as follows:
Prototype
DBMS_XMLDOM.FREEDOCUMENT ( doc IN DOMDocument );
Parameter
Parameter | Description |
---|---|
doc | Document to free the resources for. |
Example
declare doc dbms_xmldom.DOMDocument; begin doc := dbms_xmldom.newDomDocument; dbms_xmldom.freedocument(doc); end; /
Frees resources associated with the specified DOMNode. If the DOMNode is a document, the DOMNode object is initialized and the document and its resources are freed. Otherwise, only the DOMNode object is initialized.
Details about the FREENODE procedure are as follows:
Prototype
DBMS_XMLDOM.FREENODE ( n IN DOMNode );
Parameter
Parameter | Description |
---|---|
n | Node to free resources for. |
Example
declare doc dbms_xmldom.DOMDocument; begin doc := dbms_xmldom.newDomDocument; dbms_xmldom.freenode(dbms_xmldom.makeNode(doc)); end; /
Gets the attribute value of the specified Element.
Details about the GETATTRIBUTE function are as follows:
Prototype
DBMS_XMLDOM.GETATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2 ) RETURN VARCHAR2;
DBMS_XMLDOM.GETATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN VARCHAR2;
Parameters
Parameter | Description |
---|---|
elem | Element of the specified attribute. |
name | Attribute name. |
ns | Attribute namespace. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; x XMLType; attr_val VARCHAR2; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr_val := dbms_xmldom.getAttribute(ele, 'attr1'); dbms_output.put_line(attr_val); end; /
Gets the specified DOMAttr of the Element.
Details about the GETATTRIBUTENODE function are as follows:
Prototypes
DBMS_XMLDOM.GETATTRIBUTENODE ( elem IN DOMElement, name IN VARCHAR2 ) RETURN DOMAttr;
DBMS_XMLDOM.GETATTRIBUTENODE ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN DOMAttr;
Parameters
Parameter | Description |
---|---|
elem | Element of the attribute. |
name | Attribute name. |
ns | Attribute namespace. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr := dbms_xmldom.getAttributeNode(ele, 'attr1'); end; /
Gets all attributes of the specified Element.
Details about the GETATTRIBUTES function are as follows:
Prototype
DBMS_XMLDOM.GETATTRIBUTES ( n IN DOMNode ) RETURN DOMNamedNodeMap;
Parameter
Parameter | Description |
---|---|
n | Must be a DOMNode Element. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; nm dbms_xmldom.DOMNamedNodeMap; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); dbms_xmldom.setAttribute(ele, 'attr2'); nm := dbms_xmldom.getAttributes(dbms_xmldom.makeNode(ele)); end; /
Gets the child nodes of the specified node.
Details about the GETCHILDNODES function are as follows:
Prototype
DBMS_XMLDOM.GETCHILDNODES ( n IN DOMNode ) RETURN DOMNodeList;
Parameter
Parameter | Description |
---|---|
n | Parent node to get the child nodes for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; nl dbms_xmldom.DOMNodeList; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); nl := dbms_xmldom.getChildNodes(p); end; /
Gets the child nodes that contain elements with the specified tagname.
Details about the GETCHILDRENBYTAGNAME function are as follows:
Prototypes
DBMS_XMLDOM.GETCHILDRENBYTAGNAME ( elem IN DOMElement, name IN VARCHAR2 ) RETURN DOMNodeList;
DBMS_XMLDOM.GETCHILDRENBYTAGNAME ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN DOMNodeList;
Parameters
Parameter | Description |
---|---|
elem | Parent element node of the child nodes. |
name | Tagname to search for. |
ns | Namespace to search for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; nl dbms_xmldom.DOMNodeList; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); nl := dbms_xmldom.getChildrenByTagName(p, 'child1'); end; /
Gets the root element of the specified document.
Details about the GETDOCUMENTELEMENT function are as follows:
Prototype
DBMS_XMLDOM.GETDOCUMENTELEMENT ( doc IN DOMDocument ) RETURN DOMElement;
Parameter
Parameter | Description |
---|---|
doc | Document to get the root element for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); n := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getDocumentElement(doc); end; /
Gets the elements with the specified tagname.
Details about the GETELEMENTSBYTAGNAME function are as follows:
Prototypes
DBMS_XMLDOM.GETELEMENTSBYTAGNAME ( doc IN DOMDocument, name IN VARCHAR2 ) RETURN DOMNodeList;
DBMS_XMLDOM.GETELEMENTSBYTAGNAME ( elem IN DOMElement, name IN VARCHAR2 ) RETURN DOMNodeList;
DBMS_XMLDOM.GETELEMENTSBYTAGNAME ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN DOMNodeList;
Parameters
Parameter | Description |
---|---|
doc | Document node to get the elements for. |
elem | Parent element node of the child Elements. |
name | Tagname to search for. |
ns | Namespace to search for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; nl dbms_xmldom.DOMNodeList; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); nl := dbms_xmldom.getElementsByTagname(doc, 'child1'); end; /
Gets the first child node.
Details about the GETFIRSTCHILD function are as follows:
Prototype
DBMS_XMLDOM.GETFIRSTCHILD ( n IN DOMNode ) RETURN DOMNode;
Parameter
Parameter | Description |
---|---|
n | Parent node to get the child node for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getFirstChild(p); end; /
Gets the last child node.
Details about the GETLASTCHILD function are as follows:
Prototype
DBMS_XMLDOM.GETLASTCHILD ( n IN DOMNode ) RETURN DOMNode;
Parameter
Parameter | Description |
---|---|
n | Parent node to get the child node for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getLastChild(p); end; /
Gets the number of characters for CharacterData, and the number of nodes for DOMNamedNodeMap or DOMNodeList.
Details about the GETLENGTH function are as follows:
Prototypes
DBMS_XMLDOM.GETLENGTH ( cd IN DOMCharacterData ) RETURN NUMBER;
DBMS_XMLDOM.GETLENGTH ( nnm IN DOMNamedNodeMap ) RETURN NUMBER;
DBMS_XMLDOM.GETLENGTH ( nl IN DOMNodeList ) RETURN NUMBER;
Parameters
Parameter | Description |
---|---|
cd | Node of the CharacterData. |
nnm | Type that represents multiple node information in a Map. |
nl | Type that represents multiple node information in a List. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; nl dbms_xmldom.DOMNodeList; len Number; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); nl := dbms_xmldom.getElementsByTagname(doc, 'child1'); len := dbms_xmldom.getLength(nl); end; /
Gets the name of the specified node.
Details about the GETNAME function are as follows:
Prototypes
DBMS_XMLDOM.GETNAME ( a IN DOMAttr ) RETURN VARCHAR2;
DBMS_XMLDOM.GETNAME ( dt IN DOMDocumentType ) RETURN VARCHAR2;
Parameters
Parameter | Description |
---|---|
a | Attribute node. |
dt | DOMDocumentType node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr := dbms_xmldom.getAttributeNode(ele, 'attr1'); dbms_output.put_line(dbms_xmldom.getName(attr)); end; /
Gets the specified node from DOMNamedNodeMap.
Details about the GETNAMEDITEM function are as follows:
Prototypes
DBMS_XMLDOM.GETNAMEDITEM ( nnm IN DOMNamedNodeMap, name IN VARCHAR2 ) RETURN DOMNode;
DBMS_XMLDOM.GETNAMEDITEM ( nnm IN DOMNamedNodeMap, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
nnm | DOMNamedNodeMap. |
name | Name of the node. |
ns | Namespace of the node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; nm dbms_xmldom.DOMNamedNodeMap; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); dbms_xmldom.setAttribute(ele, 'attr2'); nm := dbms_xmldom.getAttributes(dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getNamedItem(nm, 'attr1'); end; /
Gets the name of the specified node.
Details about the GETNODENAME function are as follows:
Prototype
DBMS_XMLDOM.GETNODENAME ( n IN DOMNode ) RETURN VARCHAR2;
Parameter
Parameter | Description |
---|---|
n | Name of the node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; nm dbms_xmldom.DOMNamedNodeMap; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); dbms_xmldom.setAttribute(ele, 'attr2'); nm := dbms_xmldom.getAttributes(dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getNamedItem(nm, 'attr1'); dbms_output.put_line(dbms_xmldom.getNodeName(n)); end; /
Gets the DBMS_XMLDOM constant that represents the node type.
Details about the GETNODETYPE function are as follows:
Prototype
DBMS_XMLDOM.GETNODETYPE ( n IN DOMNode ) RETURN NUMBER;
Parameter
Parameter | Description |
---|---|
n | Node to get the type information for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_output.put_line(dbms_xmldom.getNodeType(dbms_xmldom.makeNode(doc))); dbms_output.put_line(dbms_xmldom.getNodeType(dbms_xmldom.makeNode(ele))); end; /
Gets the value of the specified node.
Details about the GETNODEVALUE function are as follows:
Prototype
DBMS_XMLDOM.GETNODEVALUE ( n IN DOMNode ) RETURN VARCHAR2;
Parameter
Parameter | Description |
---|---|
n | Node to get the value for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_output.put_line(dbms_xmldom.getNodeValue(dbms_xmldom.makeNode(ele))); end; /
Gets the document of the specified node.
Details about the GETOWNERDOCUMENT function are as follows:
Prototype
DBMS_XMLDOM.GETOWNERDOCUMENT ( n IN DOMNode ) RETURN DOMDocument;
Parameter
Parameter | Description |
---|---|
n | Node to get the document for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); doc := dbms_xmldom.getOwnerDocument(dbms_xmldom.makeNode(ele)); end; /
Gets the parent node of the specified node.
Details about the GETPARENTNODE function are as follows:
Prototype
DBMS_XMLDOM.GETPARENTNODE ( n IN DOMNode ) RETURN DOMNode;
Parameter
Parameter | Description |
---|---|
n | Node to get the parent for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; n1 dbms_xmldom.DOMNode; n2 dbms_xmldom.DOMNode; n3 dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n1 := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n2 := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n3 := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); n := dbms_xmldom.getParentNode(n1); end; /
Gets the value of the specified attribute node.
Details about the GETVALUE function are as follows:
Prototype
DBMS_XMLDOM.GETVALUE ( a IN DOMAttr ) RETURN VARCHAR2;
Parameter
Parameter | Description |
---|---|
a | Attribute node to get the value for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; attr dbms_xmldom.DOMAttr; attr_val VARCHAR2; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr := dbms_xmldom.getAttributeNode(ele, 'attr1'); attr_val := dbms_xmldom.getVal(attr); dbms_output.put_line(attr_val); end; /
Gets the XMLType of the Document.
Details about the GETXMLTYPE function are as follows:
Prototype
DBMS_XMLDOM.GETXMLTYPE ( doc IN DOMDocument ) RETURN XMLType;
Parameter
Parameter | Description |
---|---|
doc | DOM document to get the XMLTYPE for. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; x XMLType; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); n := dbms_xmldom.makeNode(ele); n := dbms_xmldom.appendChild(root, n); x := dbms_xmldom.getXMLType(doc); end; /
Checks if the specified element node has a specific ATTRIBUTE.
Details about the HASATTRIBUTE function are as follows:
Prototypes
DBMS_XMLDOM.HASATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2 ) RETURN BOOLEAN;
DBMS_XMLDOM.HASATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 ) RETURN BOOLEAN;
Parameters
Parameter | Description |
---|---|
elem | Element to find the attribute in. |
name | Attribute name. |
ns | Attribute namespace. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; x XMLType; has_attr BOOLEAN; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); has_attr := dbms_xmldom.HasAttribute(ele, 'attr1'); end; /
Imports a node from another document and returns it as a new node.
Details about the IMPORTNODE function are as follows:
Prototype
DBMS_XMLDOM.IMPORTNODE ( doc IN DOMDocument, importedNode IN DOMNode, deep IN BOOLEAN ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
doc | Document from which to import the node from. |
importedNode | Node to import. |
deep |
|
Example
declare doc1 dbms_xmldom.DOMDocument; doc2 dbms_xmldom.DOMDocument; ele1 dbms_xmldom.DOMElement; ele2 dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n0 dbms_xmldom.DOMNode; n1 dbms_xmldom.DOMNode; n2 dbms_xmldom.DOMNode; begin doc1 := dbms_xmldom.newDomDocument; doc2 := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc1); ele1 := dbms_xmldom.createElement(doc1, 'root'); ele2 := dbms_xmldom.createElement(doc1, 'ele'); n1 := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele1)); n2 := dbms_xmldom.appendChild(n1, dbms_xmldom.makeNode(ele2)); n0 := dbms_xmldom.importNode(doc2, n1, FALSE); end; /
Imports a node before the specified node. If the specified node is Null, inserts the node at the end of all child nodes.
Details about the INSERTBEFORE function are as follows:
Prototype
DBMS_XMLDOM.INSERTBEFORE ( n IN DOMNode, newchild IN DOMNode, refchild IN DOMNode ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
n | Parent node of the refchild node. |
newchild | Child to insert. |
refchild | newchild node is inserted before the refchild node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; ele1 dbms_xmldom.DOMElement; ele2 dbms_xmldom.DOMElement; ele3 dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; nele dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; n1 dbms_xmldom.DOMNode; n2 dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); ele1 := dbms_xmldom.createElement(doc, 'ele1'); ele2 := dbms_xmldom.createElement(doc, 'ele2'); ele3 := dbms_xmldom.createElement(doc, 'ele3'); nele := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); n1 := dbms_xmldom.appendChild(nele, dbms_xmldom.makeNode(ele1)); n2 := dbms_xmldom.appendChild(nele, dbms_xmldom.makeNode(ele2)); n := dbms_xmldom.insertBefore(nele, dbms_xmldom.makeNode(ele3), n1); end; /
Checks if the specified object is NULL.
Details about the ISNULL function are as follows:
Prototypes
DBMS_XMLDOM.ISNULL ( a IN DOMAttr ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( cds IN DOMCDataSection ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( cd IN DOMCharacterData ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( com IN DOMComment ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( doc IN DOMDocument ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( df IN DOMDocumentFragment ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( dt IN DOMDocumentType ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( elem IN DOMElement ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( ent IN DOMEntity ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( eref IN DOMEntityReference ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( di IN DOMImplementation ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( nnm IN DOMNamedNodeMap ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( n IN DOMNode ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( nl IN DOMNodeList ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( n IN DOMNotation ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( pi IN DOMProcessingInstruction ) RETURN BOOLEAN;
DBMS_XMLDOM.ISNULL ( t IN DOMText ) RETURN BOOLEAN;
Example
declare doc dbms_xmldom.DOMDocument; begin dbms_xmldom.isNULL(doc); doc := dbms_xmldom.newDomDocument; dbms_xmldom.isNULL(doc); end; /
Gets the item in the NamedNodeMap or NodeList.
Details about the ITEM function are as follows:
Prototypes
DBMS_XMLDOM.ITEM ( nl IN DOMNodeList, index IN Number ) RETURN DOMNode;
DBMS_XMLDOM.ITEM ( nnm IN DOMNamedNodeMap, index IN Number ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
nl | NodeList of the item. |
nnm | NamedNodeMap of the item. |
index | Index of the item. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; p dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; nl dbms_xmldom.DOMNodeList; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); p := dbms_xmldom.appendChild(root, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child1'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child2'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); ele := dbms_xmldom.createElement(doc, 'child3'); n := dbms_xmldom.appendChild(p, dbms_xmldom.makeNode(ele)); nl := dbms_xmldom.getChildNodes(p); n := dbms_xmldom.item(nl, 1); end; /
Casts the specified node to an attribute.
Details about the MAKEATTR function are as follows:
Prototype
DBMS_XMLDOM.MAKEATTR ( n IN DOMNode ) RETURN DOMAttr;
Parameter
Parameter | Description |
---|---|
n | DOMNode to cast to DOMAttr. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; attr dbms_xmldom.DOMAttr; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr := dbms_xmldom.getAttributeNode(ele, 'attr1'); n := dbms_xmldom.makeNode(attr); attr := dbms_xmldom.makeAttr(n); end; /
Casts the specified node to a Document.
Details about the MAKEDOCUMENT function are as follows:
Prototype
DBMS_XMLDOM.MAKEDOCUMENT ( n IN DOMNode ) RETURN DOMDocument;
Parameter
Parameter | Description |
---|---|
n | DOMNode to cast to DOMDocument. |
Example
declare doc dbms_xmldom.DOMDocument; root dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); doc := dbms_xmldom.makeAttr(root); end; /
Casts the specified node to an Element.
Details about the MAKEELEMENT function are as follows:
Prototype
DBMS_XMLDOM.MAKEELEMENT ( n IN DOMNode ) RETURN DOMElement;
Parameter
Parameter | Description |
---|---|
n | DOMNode to cast to DOMElement. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; n dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); n := dbms_xmldom.makeNode(ele); ele := dbms_xmldom.makeElement(n); end; /
Casts the specified document to a node.
Details about the MAKENODE function are as follows:
Prototype
DBMS_XMLDOM.MAKENODE ( doc IN DOMDocument ) RETURN DOMNode;
Parameter
Parameter | Description |
---|---|
doc | DOMDocument to cast to DOMNode. |
Example
declare doc dbms_xmldom.DOMDocument; root dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); end; /
Creates a DOM type document.
Details about the NEWDOMDOCUMENT function are as follows:
Prototype
DBMS_XMLDOM.NEWDOMDOCUMENT RETURN DOMDocument;
Example
declare doc dbms_xmldom.DOMDocument; begin doc := dbms_xmldom.newDomDocument; end; /
Removes the specified attribute from the element node.
Details about the REMOVEATTRIBUTE procedure are as follows:
Prototypes
DBMS_XMLDOM.REMOVEATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2 );
DBMS_XMLDOM.REMOVEATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2, ns IN VARCHAR2 );
Parameters
Parameter | Description |
---|---|
elem | Element of the attribute. |
name | Attribute name. |
ns | Attribute namespace. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; x XMLType; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); has_attr := dbms_xmldom.removeAttribute(ele, 'attr1'); end; /
Removes the specified child node of the node.
Details about the REMOVECHILD function are as follows:
Prototype
DBMS_XMLDOM.REMOVECHILD ( n IN DOMNode, oldchild IN DOMNode ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
n | Parent node of the child node. |
oldchild | Child node to remove. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; nele dbms_xmldom.DOMNode; deleted dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); nele := dbms_xmldom.makeNode(ele); nele := dbms_xmldom.appendChild(root, nele) deleted := dbms_xmldom.removeChild(root, nele); end; /
Replaces the specified child node of the node.
Details about the REPLACECHILD function are as follows:
Prototype
DBMS_XMLDOM.REPLACECHILD ( n IN DOMNode, newchild IN DOMNode, oldchild IN DOMNode ) RETURN DOMNode;
Parameters
Parameter | Description |
---|---|
n | Parent node of the child node. |
newchild | New child node. |
oldchild | Old child node. |
Example
declare doc dbms_xmldom.DOMDocument; ele1 dbms_xmldom.DOMElement; ele2 dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; nele1 dbms_xmldom.DOMNode; nele2 dbms_xmldom.DOMNode; replaced dbms_xmldom.DOMNode; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele1 := dbms_xmldom.createElement(doc, 'root'); ele2 := dbms_xmldom.createElement(doc, 'newroot'); nele1 := dbms_xmldom.makeNode(ele1); nele2 := dbms_xmldom.makeNode(ele2); nele1 := dbms_xmldom.appendChild(root, nele1) replaced := dbms_xmldom.replaceChild(root, nele2, nele1); end; /
Adds a new attribute to the specified element.
Details about the SETATTRIBUTE procedure are as follows:
Prototypes
DBMS_XMLDOM.SETATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2, newvalue IN VARCHAR2 );
DBMS_XMLDOM.SETATTRIBUTE ( elem IN DOMElement, name IN VARCHAR2, newvalue IN VARCHAR2, ns IN VARCHAR2 );
Parameters
Parameter | Description |
---|---|
elem | Element. |
name | Attribute name. |
newvalue | Attribute value. |
ns | Attribute namespace. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; x XMLType; attr_val VARCHAR2; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr_val := dbms_xmldom.getAttribute(ele, 'attr1'); dbms_output.put_line(attr_val); end; /
Sets the value of the specified attribute node.
Details about the SETVALUE procedure are as follows:
Prototype
DBMS_XMLDOM.SETVALUE ( a IN DOMAttr, value IN VARCHAR2 );
Parameter
Parameter | Description |
---|---|
a | Attribute node. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; attr dbms_xmldom.DOMAttr; begin doc := dbms_xmldom.newDomDocument; ele := dbms_xmldom.createElement(doc, 'root'); dbms_xmldom.setAttribute(ele, 'attr1'); attr := dbms_xmldom.getAttributeNode(ele, 'attr1'); dbms_xmldom.setVal(attr, 'new_attr'); end; /
Writes DOM document to the specified CLOB.
Details about the WRITETOCLOB procedure are as follows:
Prototype
DBMS_XMLDOM.WRITETOCLOB ( doc IN DOMDocument, cl OUT CLOB );
Parameters
Parameter | Description |
---|---|
doc | DOM type document. |
cl | CLOB to write to. |
Example
declare doc dbms_xmldom.DOMDocument; ele dbms_xmldom.DOMElement; root dbms_xmldom.DOMNode; n dbms_xmldom.DOMNode; cl CLOB; begin doc := dbms_xmldom.newDomDocument; root := dbms_xmldom.makeNode(doc); ele := dbms_xmldom.createElement(doc, 'root'); n := dbms_xmldom.makeNode(ele); n := dbms_xmldom.appendChild(root, n); dbms_xmldom.writeToClob(doc, cl); end; /