| Oracle9i XML API Reference - XDK and Oracle XML DB Release 2 (9.2) Part Number A96616-01 |
|
The Extensible Markup Language (XML) Parser for PL/SQL, found in the DBMS_XMLDOM Package, is used to access XMLType objects and both schema-based and nonschema-based documents.
This chapter details the following:
The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. In the DOM specification, the term "document" is used in the broad sense. XML is increasingly being used as a way of representing many different kinds of information that may be stored in diverse systems, and much of this would traditionally be seen as data rather than as documents. Nevertheless, XML presents this data as documents, and the DOM may be used to manage this data.
With the Document Object Model, programmers can build documents, navigate their structure, and add, modify, or delete elements and content. Anything found in an HTML or XML document can be accessed, changed, deleted, or added using the Document Object Model, with a few exceptions. In particular, the DOM interfaces for the XML internal and external subsets have not yet been specified.
One important objective of the W3C specification for the Document Object Model is to provide a standard programming interface that can be used in a wide variety of environments and applications. The DOM is designed to be used with any programming language. Since the DOM standard is object-oriented, for this PL/SQL adaptation, some changes had to be made:
appendChild() PL/SQL function is provided,
FUNCTION appendChild( n DOMNode, newChild IN DOMNode) RETURN DOMNode;
and to perform setAttribute on a DOM Element elem, the setAttribute() PL/SQL procedure is provided:
PROCEDURE setAttribute( elem DOMElement, name IN VARCHAR2, value IN VARCHAR2);
DOM defines an inheritance hierarchy. For example, Document, Element, and Attr are defined to be subtypes of Node. Thus, a method defined in the Node interface should be available in these as well. Since, such inheritance is not directly possible in PL/SQL, the makeNode functions need to be invoked on different DOM types to convert these into a DOMNode. The appropriate functions or procedures that accept DOMNodes can then be called to operate on these types. If, subsequently, type specific functionality is desired, the DOMNode can be converted back into the type by using the make*() functions, where DOM* is the desired DOM type.
The implementation of this PL/SQL DOM interface followed the DOM standard of revision REC-DOM-Level-1-19981001. The types and methods described in this document are made available by the PL/SQL package DBMS_XMLDOM.
initialization.ORA file must be specified; for example:
UTL_FILE_DIR=/mypath/insidemypath
The following types are defined for DBMS_XMLDOM.DOMTYPE:
The constants listed in Table 25-2 are defined for DBMS_XMLDOM. For example, when a request such as getNodeType(myNode) is made, the returned type will be one of the following constants.
The exceptions listed in Table 25-3 are defined for DBMS_XMLDOM:
DBMS_XMLDOM subprograms are divided into groups according to w3c Interfaces.
Checks if the given DOMNode is NULL. Returns TRUE if it is NULL, FALSE otherwise.
FUNCTION isNull( n DOMNode) RETURN BOOLEAN;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to check. |
Casts a given DOMNode to a DOMAttr, and returns the DOMAttr.
FUNCTION makeAttr( n DOMNode) RETURN DOMAttr;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMCDataSection, and returns the DOMCDataSection.
FUNCTION makeCDataSection( n DOMNode) RETURN DOMCDataSection;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMCharacterData, and returns the DOMCharacterData.
FUNCTION makeCharacterData( n DOMNode) RETURN DOMCharacterData;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMComment, and returns the DOMComment.
FUNCTION makeComment(n DOMNode) RETURN DOMComment;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMDocumentFragment, and returns the DOMDocumentFragment.
FUNCTION makeDocumentFragment( n DOMNode) RETURN DOMDocumentFragment;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMDocumentType and returns the DOMDocumentType.
FUNCTION makeDocumentType(n DOMNode) RETURN DOMDocumentType;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMElement, and returns the DOMElement.
FUNCTION makeElement(n DOMNode) RETURN DOMElement;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMEntity, and returns the DOMEntity.
FUNCTION makeEntity(n DOMNode) RETURN DOMEntity;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMEntityReference, and returns the DOMEntityReference.
FUNCTION makeEntityReference(n DOMNode) RETURN DOMEntityReference;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMNotation, and returns the DOMNotation.
FUNCTION makeNotation(n DOMNode) RETURN DOMNotation;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMProcessingInstruction, and returns the DOMProcessingInstruction.
FUNCTION makeProcessingInstruction( n DOMNode) RETURN DOMProcessingInstruction;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMText, and returns the DOMText.
FUNCTION makeText(n DOMNode) RETURN DOMText;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Casts a given DOMNode to a DOMDocument, and returns the DOMDocument.
FUNCTION makeDocument(n DOMNode) RETURN DOMDocument;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode to cast |
Writes XML node to specified file. The options are given in the following table.
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode. |
|
fileName |
(IN) |
File to write to. |
|
charset |
(IN) |
Given character set. |
Writes XML node to specified buffer. The options are given in the following table.
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode. |
|
buffer |
(IN/OUT) |
Buffer to write to. |
|
charset |
(IN) |
Given character set. |
Writes XML node to specified clob. The options are given in the following table.
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
(IN) |
DOMNode. |
|
cl |
(IN/OUT) |
CLOB to write to. |
|
charset |
(IN) |
Given character set. |
Get the name of the node depending on its type
FUNCTION getNodeName(n DOMNode) RETURN VARCHAR2;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
IN |
DOMNode |
Get the value of this node, depending on its type.
FUNCTION getNodeValue(n DOMNode) RETURN VARCHAR2;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
IN |
DOMNode. |
Sets the value of this node, depending on its type. When it is defined to be null, setting it has no effect.
PROCEDURE setNodeValue( n DOMNode, nodeValue IN VARCHAR2);
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |
IN |
DOMNode. |
|
nodeValue |
IN |
The value to which node is set. |
Retrieves a code representing the type of the underlying object.
FUNCTION getNodeType(n DOMNode) RETURN NUMBER;
| Parameter | IN / OUT | Description |
|---|---|---|
|
n |