コード例 #1
0
 public static Task <int> ReadAsynchronous(this OracleXmlStream xmlStream, char[] buffer, int offset, int count, CancellationToken cancellationToken)
 {
     return(App.ExecuteAsynchronous(delegate { }, () => xmlStream.Read(buffer, offset, count), cancellationToken));
 }
コード例 #2
0
ファイル: XMLTypeDemo.cs プロジェクト: leed25d/golden
        /// <summary>
        /// Demonstrate the properties and methods on OracleXmlType
        /// </summary>
        /// <param name="connectStr"></param>
        /// <returns></returns>
        public static void PropDemo(OracleXmlType xml)
        {
            try
            {
                // Value property
                Console.WriteLine("Value property: ");
                Console.WriteLine(xml.Value);
                Console.WriteLine("");

                // Get an Oracle XML Stream
                OracleXmlStream strm = xml.GetStream();
                Console.WriteLine("GetStream() method: ");
                Console.WriteLine(strm.Value);
                Console.WriteLine("");
                strm.Dispose();

                // Get a .NET XmlReader
                XmlReader   xmlRdr        = xml.GetXmlReader();
                XmlDocument xmlDocFromRdr = new XmlDocument();
                xmlDocFromRdr.Load(xmlRdr);
                Console.WriteLine("GetXmlReader() method: ");
                Console.WriteLine(xmlDocFromRdr.OuterXml);
                Console.WriteLine("");
                xmlDocFromRdr = null;
                xmlRdr        = null;

                // Get a .NET XmlDocument
                XmlDocument xmlDoc = xml.GetXmlDocument();
                Console.WriteLine("GetXmlDocument() method: ");
                Console.WriteLine(xmlDoc.OuterXml);
                Console.WriteLine("");
                xmlDoc = null;

                // IsExists method
                string xpathexpr = "/PO/SHIPADDR";
                string nsmap     = null;
                if (xml.IsExists(xpathexpr, nsmap))
                {
                    // Extract method
                    OracleXmlType xmle = xml.Extract(xpathexpr, nsmap);

                    // IsEmpty property
                    if (xmle.IsEmpty)
                    {
                        Console.WriteLine("Extract() method returns empty xml data");
                    }
                    else
                    {
                        Console.WriteLine("Extracted XML data: ");
                        Console.WriteLine(xmle.Value);
                    }
                    Console.WriteLine("");
                    xmle.Dispose();
                }

                // Use XSLT on the OracleXmlType
                StringBuilder blr = new StringBuilder();
                blr.Append("<?xml version=\"1.0\"?> ");
                blr.Append("<xsl:stylesheet version=\"1.0\" ");
                blr.Append("xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"> ");
                blr.Append(" <xsl:template match=\"/\"> ");
                blr.Append(" <NEWPO> ");
                blr.Append(" <xsl:apply-templates select=\"PO\"/> ");
                blr.Append(" </NEWPO> ");
                blr.Append(" </xsl:template> ");
                blr.Append(" <xsl:template match=\"PO\"> ");
                blr.Append(" <xsl:apply-templates select=\"CUSTNAME\"/> ");
                blr.Append(" </xsl:template> ");
                blr.Append(" <xsl:template match=\"CUSTNAME\"> ");
                blr.Append(" <CNAME> <xsl:value-of select=\".\"/> </CNAME> ");
                blr.Append(" </xsl:template> </xsl:stylesheet> ");

                string        pmap = null;
                OracleXmlType xmlt = xml.Transform(blr.ToString(), pmap);

                //Print the transformed xml data
                Console.WriteLine("XML Data after Transform(): ");
                Console.WriteLine(xmlt.Value);

                // Update the CNAME in the transformed xml data
                xpathexpr = "/NEWPO/CNAME/text()";
                xmlt.Update(xpathexpr, nsmap, "NewName");

                // See the updated xml data
                Console.WriteLine("XML Data after Update(): ");
                Console.WriteLine(xmlt.Value);
                Console.WriteLine("");

                xmlt.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // Create the connection.
            string           constr = "User Id=scott;Password=tiger;Data Source=oracle";
            OracleConnection con    = new OracleConnection(constr);

            con.Open();

            // Create an OracleXmlType from String
            StringBuilder blr = new StringBuilder();

            blr.Append("<?xml version=\"1.0\"?> <PO pono=\"1\"> ");
            blr.Append("<PNAME>Po_1</PNAME> <CUSTNAME>John</CUSTNAME> ");
            blr.Append("<SHIPADDR> <STREET>1033, Main Street</STREET> ");
            blr.Append("<CITY>Sunnyvale</CITY> <STATE>CA</STATE> </SHIPADDR> ");
            blr.Append("</PO>");

            // Create a OracleXmlStream from OracleXmlType
            OracleXmlType   xml  = new OracleXmlType(con, blr.ToString());
            OracleXmlStream strm = new OracleXmlStream(xml);

            // Print the length of xml data in the stream
            Console.WriteLine("OracleXmlStream Length: " + strm.Length);
            Console.WriteLine("");

            // Print the xml data in the stream
            Console.WriteLine("OracleXmlStream Value: " + strm.Value);
            Console.WriteLine("");

            // Check CanRead property on the stream
            Console.WriteLine("OracleXmlStream CanRead: " + strm.CanRead);
            Console.WriteLine("");

            // Check CanWrite property on the stream
            Console.WriteLine("OracleXmlStream CanWrite: " + strm.CanWrite);
            Console.WriteLine("");

            // Print current position in stream
            Console.WriteLine("OracleXmlStream Position: " + strm.Position);
            Console.WriteLine("");

            // Read 10 bytes at a time from the stream
            int rb     = 0;
            int curpos = 0;

            byte[] bytebuf = new byte[500];
            while ((rb = strm.Read(bytebuf, curpos, 10)) > 0)
            {
                curpos += rb;
            }

            // Print the contents of the byte array
            System.Text.Encoding encoding = System.Text.Encoding.Unicode;
            Console.WriteLine("OracleXmlStream Read byte[]: " +
                              encoding.GetString(bytebuf));
            Console.WriteLine("");

            // Print current position in stream
            Console.WriteLine("OracleXmlStream Position: " + strm.Position);
            Console.WriteLine("");

            strm.Dispose();
            xml.Dispose();
            con.Close();
            con.Dispose();
        }