dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleXml Class
Members Example

OracleXml Class
Represents an Oracle XMLType instance.
Syntax
'Declaration
 
Public Class OracleXml 
   Implements System.Data.SqlTypes.INullableSystem.IDisposable 
 
Remarks

Use OracleXml object to represent XML data at Oracle database. Values of OracleXml type can be retrived from OracleDataReader and passed to OracleParameter object.

A number of OracleXml properties and its methods are not supported in the OracleConnection.Direct mode. See the property descriptions to determine whether they are supported in the Direct mode.

Example

This sample demonstrates how you can operate with the OracleXml class. Here a simple OracleXml object is created and inserted into the database. After that, it is shown how to transform XML via the XSL schema and extract its fragments using XPath expressions.

To run this sample, you need to execute the following script in your Oracle database:

CREATE TABLE CDs (
   ID NUMBER,
   DISC XMLTYPE
)

This sample works only with the OCI mode connection.

// Initialize and open a connection to the Oracle server
OracleConnection connection = new OracleConnection();
connection.Server = "Ora";
connection.UserId = "Scott";
connection.Password = "tiger";
connection.Open();

// Initialize an OracleXml instance with simple xml content
string content = @"
        <catalog>
        <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
        </cd>
        </catalog>
        ";
OracleXml xml = new OracleXml(content, connection);

// Insert the xml object into the table with a field of the Oracle XML type
OracleCommand command = new OracleCommand("insert into CDs(id, disc) values(10, :disc)", connection);
command.Parameters.Add(new OracleParameter("disc", xml));
command.ExecuteNonQuery();
            
// Use an XSL transformation to create an HTML page representing the content of the xml object.
string transformation = @"
        <xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">

        <xsl:template match=""/"">
        <html>
        <body>
        <h2>My CD Collection</h2>
        <table border=""1"">
        <tr bgcolor=""#9acd32"">
        <th>Title</th>
        <th>Artist</th>
        </tr>
        <xsl:for-each select=""catalog/cd"">
        <tr>
        <td><xsl:value-of select=""title""/></td>
        <td><xsl:value-of select=""artist""/></td>
        </tr>
        </xsl:for-each>
        </table>
        </body>
        </html>
        </xsl:template>

        </xsl:stylesheet>
        ";
OracleXml transformed = xml.Transform(transformation);
Console.WriteLine(transformed.Value);

// Retrieve an XML fragment by the XPath expression specified:
OracleXml extracted = xml.Extract("catalog/cd/price", "");
Console.WriteLine("The price elements:");
Console.WriteLine(extracted.Value);

Console.ReadLine();
' Initialize and open a connection to the Oracle server
Dim connection As New OracleConnection()
connection.Server = "Ora"
connection.UserId = "Scott"
connection.Password = "tiger"
connection.Open()

' Initialize an OracleXml instance with simple xml content
Dim content As String = "<catalog>" + vbCrLf + &
        "<cd>" + vbCrLf + &
        "<title>Empire Burlesque</title>" + vbCrLf + &
        "<artist>Bob Dylan</artist>" + vbCrLf + &
        "<country>USA</country>" + vbCrLf + &
        "<company>Columbia</company>" + vbCrLf + &
        "<price>10.90</price>" + vbCrLf + &
        "<year>1985</year>" + vbCrLf + &
        "</cd>" + vbCrLf + &
        "</catalog>"

Dim xml As New OracleXml(content, connection)

' Insert the xml object into the field of the Oracle XML type
Dim command As New OracleCommand("insert into CDs(id, disc) values(10, :disc)", connection)
command.Parameters.Add(New OracleParameter("disc", xml))
command.ExecuteNonQuery()

' Use an XSL transformation to create an HTML page representing the content of the xml object.
Dim transformation As String = "<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" + vbCrLf + &
        "<xsl:template match=""/"">" + vbCrLf + &
        "<html>" + vbCrLf + &
        "<body>" + vbCrLf + &
        "<h2>My CD Collection</h2>" + vbCrLf + &
        "<table border=""1"">" + vbCrLf + &
        "<tr bgcolor=""#9acd32"">" + vbCrLf + &
        "<th>Title</th>" + vbCrLf + &
        "<th>Artist</th>" + vbCrLf + &
        "</tr>" + vbCrLf + &
        "<xsl:for-each select=""catalog/cd"">" + vbCrLf + &
        "<tr>" + vbCrLf + &
        "<td><xsl:value-of select=""title""/></td>" + vbCrLf + &
        "<td><xsl:value-of select=""artist""/></td>" + vbCrLf + &
        "</tr>" + vbCrLf + &
        "</xsl:for-each>" + vbCrLf + &
        "</table>" + vbCrLf + &
        "</body>" + vbCrLf + &
        "</html>" + vbCrLf + &
        "</xsl:template>" + vbCrLf + &
        "</xsl:stylesheet>"
Dim transformed = xml.Transform(transformation)
Console.WriteLine(transformed.Value)

' Retrieve an XML fragment by the XPath expression specified:
Dim extracted = xml.Extract("catalog/cd/price", "")
Console.WriteLine("The price elements:")
Console.WriteLine(extracted.Value)

Console.ReadLine()
Inheritance Hierarchy

System.Object
   Devart.Data.Oracle.OracleXml

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also