예제 #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            string _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                _connObj.Open();
                string _data = "";
                _data = "<PRODUCT xmlns=\"PRODUCT.xsd\">" +
                        " <CATEGORY>Slipspace drives</CATEGORY>" +
                        " <PERSON_IN_CHARGE>Fujikawa</PERSON_IN_CHARGE>" +
                        " <REGIONAL_PRICING>" +
                        " <EASTASIA>5000</EASTASIA>" +
                        " <AMERICAS>8000</AMERICAS>" +
                        " </REGIONAL_PRICING> " +
                        "</PRODUCT>";
                OracleXmlType _oracleXmlType = new OracleXmlType(_connObj, _data);
                MessageBox.Show("Validation result is : " +
                                _oracleXmlType.Validate("PRODUCT.xsd"));
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
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();

            // Register the XML schema in the database
            RegisterXmlSchema(con);

            // Construct the schema based XML data
            StringBuilder blr = new StringBuilder();

            blr.Append("<?xml version=\"1.0\"?> ");
            blr.Append("<PO xmlns=\"po.xsd\" ");
            blr.Append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
            blr.Append("xsi:schemaLocation=\"po.xsd po.xsd\" 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 OracleXmlType from the schema based XML data
            OracleXmlType xml = new OracleXmlType(con, blr.ToString());

            // Print the XML data in the OracleXmlType
            Console.WriteLine("OracleXmlType Value: " + xml.Value);
            Console.WriteLine("");

            // Validate the XML data in the OracleXmlType against the schema registered
            // in the oracle database
            if (xml.Validate("po.xsd"))
            {
                Console.WriteLine("OracleXmlType Schema Validation: Success\n");
            }
            else
            {
                Console.WriteLine("OracleXmlType Schema Validation: Failed\n");
            }


            // Print the RootElement of the XML data in the oraclexmltype
            Console.WriteLine("OracleXmlType RootElement: " + xml.RootElement);
            Console.WriteLine("");

            // Print the SchemaUrl of the XML data in the oraclexmltype
            Console.WriteLine("OracleXmlType SchemaUrl: " + xml.SchemaUrl);
            Console.WriteLine("");

            // Print the XML Schema of the XML data in the oraclexmltype
            Console.WriteLine("OracleXmlType Schema: " + xml.Schema.Value);
            Console.WriteLine("");

            // Dispose the OracleXmlType
            xml.Dispose();

            // Unregister the XML schema from the database
            DeleteXmlSchema(con);

            // Close the connection
            con.Close();
            con.Dispose();
        }