Send feedback on this topic.
Teradata.Client.Provider
TdXml Class
Members  Example 



Teradata.Client.Provider Namespace : TdXml Class
TdXml represents a Xml data type. It is used to retrieve Xml data from a Teradata Vantage Advanced SQL Engine.
Object Model
TdXml ClassTdXml Class
Syntax
'Declaration
 
Public NotInheritable Class TdXml 
   Inherits System.MarshalByRefObject
   Implements System.Data.SqlTypes.INullableSystem.ICloneableSystem.IDisposable 
'Usage
 
Dim instance As TdXml
Remarks

TdXml does not expose any public constructor. It's primary purpose is to retreive Xml data from a Teradata Vantage Advanced SQL Engine.

In order to create an instance of TdXml, TdDataReader.GetTdXml must be called when the data contained in a Xml column is to be retrieved. Once a TdXml instance has been created the TdXml.CreateXmlReader method is called to create a Xml.XmlReader. The XmlReader is used to access the Xml data that is returned from a Advanced SQL Engine.

When a XmlReader is created, the provider will open a request on the existing connection. This request is separate and independent from the request that was opened to process the query. A connection has a maximum number of open requests that it can support. The limit is 16.

It is important that Xml.XmlReader.Close is called after the XmlReader has been used to process the Xml. This will free up the request that was used to retrieve the Xml from the SQL Engine.

A TdXml instance can only be created when the Xml data is retrieved using deferred mode. This allows the data to be streamed from the database to the provider, and allows an application to retrieve the data in chunks.

An application is unable to access the base stream of the TdXml instance.

Xml data is returned using deferred mode when Data.CommandBehavior.SequentialAccess has not been specified in the call to TdCommand.ExecuteReader.

Example

The following example shows how to retrieve the Xml contained in an Xml column.

The Xml that is used in this example is

<?xml version="1.0" encoding="utf-8"?> <customers> <customer> <Name id="1234">John Hancock</Name> <Address>100 1st Street One City, CA 12345</Address> <Phone1>(999)9999-999</Phone1> <Phone2>(999)9999-998</Phone2> <Fax>(999)9999-997</Fax> <Email>John@somecompany.com</Email> <order Number="NW-01-16366" Date="Feb/28/2001"> <Contact>Mary</Contact> <Phone>(987)6543-210</Phone> <ShipTo>Some company 2467 Pioneer Road Globecity, Globeland, 1000</ShipTo> <SubTotal>2355</SubTotal> <Tax>141.50</Tax> <Total>2496.50</Total> <item ID="001"> <Quantity>10</Quantity> <PartNumber>F54709</PartNumber> <Description/> <UnitPrice>29.50</UnitPrice> <Price>295.00</Price> </item> </order> </customer> </customers>

public void TdXmlExample(TdConnection conn)
{
    TdCommand cmd = conn.CreateCommand();
    cmd.CommandText = "select xmlColumn from xmlTable";
    
    // query will be executed in deferred mode.  This means 
    // that CommandBehavior.SequentialAccess will not be passed
    // in as a parameter
    
    using (TdDataReader dr = cmd.ExecuteReader())
    {
        // initializing the data reader
        dr.Read();
    
        // creating an instance of TdXml
        using (TdXml xmlData = dr.GetTdXml(0))
        {
            // after a TdXml instance is created, a XmlReader needs to be 
            // created in order to access the Xml data retrieved from the 
            // Advanced SQL Engine.
            
            using (XmlReader xReader = xmlData.CreateXmlReader())
            {
                // now the xml data can be retrieved using the XmlReader.
                // going to dump the xml document to the console using a XmlWriter
                
                using (XmlWriter xWriter = XmlWriter.Create(Console.Out))
                {
                    while (xReader.Read())
                    {
                        xWriter.WriteNode(xReader, false);
                    }
                }
            }
         }
    }
}
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      Teradata.Client.Provider.TdXml

Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdXml Members
Teradata.Client.Provider Namespace