TdXml represents a Xml data type. It is used to retrieve Xml data from
a Teradata Vantage Advanced SQL Engine.
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);
}
}
}
}
}
}
Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019