当前位置: 首页>>代码示例>>C#>>正文


C# DataTable.WriteXmlSchema方法代码示例

本文整理汇总了C#中DataTable.WriteXmlSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.WriteXmlSchema方法的具体用法?C# DataTable.WriteXmlSchema怎么用?C# DataTable.WriteXmlSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataTable的用法示例。


在下文中一共展示了DataTable.WriteXmlSchema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadWriteXmlSchemaExp_TableNameConflict

 public void ReadWriteXmlSchemaExp_TableNameConflict()
 {
     DataTable dtw = new DataTable("Table1");
     StringWriter writer1 = new StringWriter();
     dtw.WriteXmlSchema(writer1);
     DataTable dtr = new DataTable("Table2");
     StringReader reader1 = new StringReader(writer1.ToString());
     try
     {
         dtr.ReadXmlSchema(reader1);
         Assert.False(true);
     }
     catch (ArgumentException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DataTableTest.cs

示例2: ReadWriteXmlSchemaExp_NoFileName

 public void ReadWriteXmlSchemaExp_NoFileName()
 {
     DataTable dtw = new DataTable();
     try
     {
         dtw.WriteXmlSchema(string.Empty);
         Assert.False(true);
     }
     catch (ArgumentException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:DataTableTest.cs

示例3: WriteXmlSchema_Hierarchy

        public void WriteXmlSchema_Hierarchy()
        {
            var ds = new DataSet();
            DataTable table1 = new DataTable();
            DataColumn idColumn = table1.Columns.Add("ID", typeof(int));
            table1.Columns.Add("Name", typeof(string));
            table1.PrimaryKey = new DataColumn[] { idColumn };
            DataTable table2 = new DataTable();
            table2.Columns.Add(new DataColumn("OrderID", typeof(int)));
            table2.Columns.Add(new DataColumn("CustomerID", typeof(int)));
            table2.Columns.Add(new DataColumn("OrderDate", typeof(DateTime)));
            table2.PrimaryKey = new DataColumn[] { table2.Columns[0] };
            ds.Tables.Add(table1);
            ds.Tables.Add(table2);
            ds.Relations.Add("CustomerOrder",
                new DataColumn[] { table1.Columns[0] },
                new DataColumn[] { table2.Columns[1] }, true);

            StringWriter writer1 = new StringWriter();
            table1.WriteXmlSchema(writer1, false);
            string expected1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n  <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\n    <xs:complexType>\n      <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\n        <xs:element name=\"Table1\">\n          <xs:complexType>\n            <xs:sequence>\n              <xs:element name=\"ID\" type=\"xs:int\" />\n              <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\n            </xs:sequence>\n          </xs:complexType>\n        </xs:element>\n      </xs:choice>\n    </xs:complexType>\n    <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\n      <xs:selector xpath=\".//Table1\" />\n      <xs:field xpath=\"ID\" />\n    </xs:unique>\n  </xs:element>\n</xs:schema>";
            Assert.Equal(expected1, writer1.ToString().Replace("\r\n", "\n"));

            StringWriter writer2 = new StringWriter();
            table1.WriteXmlSchema(writer2, true);
            string expected2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n  <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\n    <xs:complexType>\n      <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\n        <xs:element name=\"Table1\">\n          <xs:complexType>\n            <xs:sequence>\n              <xs:element name=\"ID\" type=\"xs:int\" />\n              <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\n            </xs:sequence>\n          </xs:complexType>\n        </xs:element>\n        <xs:element name=\"Table2\">\n          <xs:complexType>\n            <xs:sequence>\n              <xs:element name=\"OrderID\" type=\"xs:int\" />\n              <xs:element name=\"CustomerID\" type=\"xs:int\" minOccurs=\"0\" />\n              <xs:element name=\"OrderDate\" type=\"xs:dateTime\" minOccurs=\"0\" />\n            </xs:sequence>\n          </xs:complexType>\n        </xs:element>\n      </xs:choice>\n    </xs:complexType>\n    <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\n      <xs:selector xpath=\".//Table1\" />\n      <xs:field xpath=\"ID\" />\n    </xs:unique>\n    <xs:unique name=\"Table2_Constraint1\" msdata:ConstraintName=\"Constraint1\" msdata:PrimaryKey=\"true\">\n      <xs:selector xpath=\".//Table2\" />\n      <xs:field xpath=\"OrderID\" />\n    </xs:unique>\n    <xs:keyref name=\"CustomerOrder\" refer=\"Constraint1\">\n      <xs:selector xpath=\".//Table2\" />\n      <xs:field xpath=\"CustomerID\" />\n    </xs:keyref>\n  </xs:element>\n</xs:schema>";
            Assert.Equal(expected2, writer2.ToString().Replace("\r\n", "\n"));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:28,代码来源:DataTableTest.cs

示例4: ReadWriteXmlSchemaExp_NoTableName

 public void ReadWriteXmlSchemaExp_NoTableName()
 {
     DataTable dtw = new DataTable();
     MemoryStream ms = new MemoryStream();
     try
     {
         dtw.WriteXmlSchema(ms);
         Assert.False(true);
     }
     catch (InvalidOperationException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:DataTableTest.cs

示例5: TestWriteXmlSchema3

        public void TestWriteXmlSchema3()
        {
            DataTable dt = new DataTable("TestWriteXmlSchema");
            dt.Columns.Add("Col1", typeof(int));
            dt.Columns.Add("Col2", typeof(int));
            DataRow dr = dt.NewRow();
            dr[0] = 10;
            dr[1] = 20;
            dt.Rows.Add(dr);
            DataTable dt1 = new DataTable("HelloWorld");
            dt1.Columns.Add("T1", typeof(int));
            dt1.Columns.Add("T2", typeof(int));
            DataRow dr1 = dt1.NewRow();
            dr1[0] = 10;
            dr1[1] = 20;
            dt1.Rows.Add(dr1);
            var ds = new DataSet();
            ds.Tables.Add(dt);
            ds.Tables.Add(dt1);
            DataRelation rel = new DataRelation("Relation1", dt.Columns["Col1"], dt1.Columns["T1"]);
            ds.Relations.Add(rel);
            TextWriter writer = new StringWriter();
            dt.WriteXmlSchema(writer, true);
            string TextString = writer.ToString();
            string substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-16\"?>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">", substring);
            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("  <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"TestWriteXmlSchema\" msdata:UseCurrentLocale=\"true\">", substring);
            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("    <xs:complexType>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("      <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("        <xs:element name=\"TestWriteXmlSchema\">", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("          <xs:complexType>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("            <xs:sequence>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("              <xs:element name=\"Col1\" type=\"xs:int\" minOccurs=\"0\" />", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("              <xs:element name=\"Col2\" type=\"xs:int\" minOccurs=\"0\" />", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("            </xs:sequence>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("          </xs:complexType>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("        </xs:element>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("        <xs:element name=\"HelloWorld\">", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("          <xs:complexType>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("            <xs:sequence>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("              <xs:element name=\"T1\" type=\"xs:int\" minOccurs=\"0\" />", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("              <xs:element name=\"T2\" type=\"xs:int\" minOccurs=\"0\" />", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
            Assert.Equal("            </xs:sequence>", substring);

            substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
            TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
//.........这里部分代码省略.........
开发者ID:dotnet,项目名称:corefx,代码行数:101,代码来源:DataTableTest.cs


注:本文中的DataTable.WriteXmlSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。