本文整理汇总了C#中DataSet.WriteXmlSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.WriteXmlSchema方法的具体用法?C# DataSet.WriteXmlSchema怎么用?C# DataSet.WriteXmlSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.WriteXmlSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteXmlSchema7
public void WriteXmlSchema7()
{
var ds = new DataSet();
DataTable dt = new DataTable("table");
dt.Columns.Add("col1");
dt.Columns.Add("col2");
ds.Tables.Add(dt);
dt.Rows.Add(new object[] { "foo", "bar" });
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
Assert.True(sw.ToString().IndexOf("xmlns=\"\"") > 0);
}
示例2: WriteXmlExtendedProperties
public void WriteXmlExtendedProperties()
{
string xml = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""NewDataSet"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:msprop=""urn:schemas-microsoft-com:xml-msprop"">
" +
@" <xs:element name=""NewDataSet"" msdata:IsDataSet=""true"" msdata:UseCurrentLocale=""true"" msprop:version=""version 2.1"">"
+ @"
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""Foo"">
<xs:complexType>
<xs:sequence>
<xs:element name=""col1"" type=""xs:string"" minOccurs=""0"" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
var ds = new DataSet();
ds.ExtendedProperties["version"] = "version 2.1";
DataTable dt = new DataTable("Foo");
dt.Columns.Add("col1");
dt.Rows.Add(new object[] { "foo" });
ds.Tables.Add(dt);
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xml.Replace("\r\n", "\n"));
}
示例3: WriteXmlSchema5
public void WriteXmlSchema5()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
" +
" <xs:element name=\"Example\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\""
+ @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""StandAlone"">
<xs:complexType>
<xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Desc"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
<xs:element name=""Dimension"">
<xs:complexType>
<xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
<xs:element name=""Element"">
<xs:complexType>
<xs:attribute name=""Dimension"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name=""PK_Dimension"" msdata:PrimaryKey=""true"">
<xs:selector xpath="".//Dimension"" />
<xs:field xpath=""@Number"" />
</xs:unique>
<xs:unique name=""PK_Element"" msdata:PrimaryKey=""true"">
<xs:selector xpath="".//Element"" />
<xs:field xpath=""@Dimension"" />
<xs:field xpath=""@Number"" />
</xs:unique>
<xs:keyref name=""FK_Element_To_Dimension"" refer=""PK_Dimension"">
<xs:selector xpath="".//Element"" />
<xs:field xpath=""@Dimension"" />
</xs:keyref>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add a DataTable with no ReadOnly columns
DataTable dt1 = new DataTable("StandAlone");
ds.Tables.Add(dt1);
// Add a ReadOnly column
dt1.Columns.Add(new DataColumn("ID", typeof(int), "",
MappingType.Attribute));
dt1.Columns["ID"].AllowDBNull = false;
dt1.Columns.Add(new DataColumn("Desc", typeof
(string), "", MappingType.Attribute));
dt1.Columns["Desc"].AllowDBNull = false;
// Add related DataTables with ReadOnly columns
DataTable dt2 = new DataTable("Dimension");
ds.Tables.Add(dt2);
dt2.Columns.Add(new DataColumn("Number", typeof
(int), "", MappingType.Attribute));
dt2.Columns["Number"].AllowDBNull = false;
dt2.Columns["Number"].ReadOnly = true;
dt2.Columns.Add(new DataColumn("Title", typeof
(string), "", MappingType.Attribute));
dt2.Columns["Title"].AllowDBNull = false;
dt2.Constraints.Add("PK_Dimension", dt2.Columns["Number"], true);
DataTable dt3 = new DataTable("Element");
ds.Tables.Add(dt3);
dt3.Columns.Add(new DataColumn("Dimension", typeof
(int), "", MappingType.Attribute));
dt3.Columns["Dimension"].AllowDBNull = false;
dt3.Columns["Dimension"].ReadOnly = true;
dt3.Columns.Add(new DataColumn("Number", typeof
(int), "", MappingType.Attribute));
dt3.Columns["Number"].AllowDBNull = false;
dt3.Columns["Number"].ReadOnly = true;
dt3.Columns.Add(new DataColumn("Title", typeof
(string), "", MappingType.Attribute));
dt3.Columns["Title"].AllowDBNull = false;
dt3.Constraints.Add("PK_Element", new DataColumn[] {
dt3.Columns ["Dimension"],
dt3.Columns ["Number"] }, true);
ds.Relations.Add("FK_Element_To_Dimension",
dt2.Columns["Number"], dt3.Columns["Dimension"]);
ds.AcceptChanges();
//.........这里部分代码省略.........
示例4: WriteXmlSchema6
public void WriteXmlSchema6()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
" +
@" <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:UseCurrentLocale=""true"""
+ @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""MyType"">
<xs:complexType>
<xs:attribute name=""Desc"">
<xs:simpleType>
<xs:restriction base=""xs:string"">
<xs:maxLength value=""32"" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add MyType DataTable
ds.Tables.Add("MyType");
ds.Tables["MyType"].Columns.Add(new DataColumn(
"Desc", typeof(string), "", MappingType.Attribute));
ds.Tables["MyType"].Columns["Desc"].MaxLength = 32;
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xmlschema.Replace("\r\n", "\n"));
}
示例5: WriteXmlSchema3
public void WriteXmlSchema3()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""ExampleDataSet"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
<xs:element name=""ExampleDataSet"" msdata:IsDataSet=""true"" ";
xmlschema = xmlschema + "msdata:UseCurrentLocale=\"true\"";
xmlschema = xmlschema + @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""ExampleDataTable"">
<xs:complexType>
<xs:attribute name=""PrimaryKeyColumn"" type=""xs:int"" use=""required"" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name=""PK_ExampleDataTable"" msdata:PrimaryKey=""true"">
<xs:selector xpath="".//ExampleDataTable"" />
<xs:field xpath=""@PrimaryKeyColumn"" />
</xs:unique>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("ExampleDataSet");
ds.Tables.Add(new DataTable("ExampleDataTable"));
ds.Tables["ExampleDataTable"].Columns.Add(
new DataColumn("PrimaryKeyColumn", typeof(int), "", MappingType.Attribute));
ds.Tables["ExampleDataTable"].Columns["PrimaryKeyColumn"].AllowDBNull = false;
ds.Tables["ExampleDataTable"].Constraints.Add(
"PK_ExampleDataTable",
ds.Tables["ExampleDataTable"].Columns["PrimaryKeyColumn"],
true);
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xmlschema.Replace("\r\n", "\n"));
}
示例6: WriteXmlSchema4
public void WriteXmlSchema4()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
";
xmlschema = xmlschema + " <xs:element name=\"Example\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\"";
xmlschema = xmlschema + @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""MyType"">
<xs:complexType>
<xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Desc"" type=""xs:string"" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add MyType DataTable
DataTable dt = new DataTable("MyType");
ds.Tables.Add(dt);
dt.Columns.Add(new DataColumn("ID", typeof(int), "",
MappingType.Attribute));
dt.Columns["ID"].AllowDBNull = false;
dt.Columns.Add(new DataColumn("Desc", typeof
(string), "", MappingType.Attribute));
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xmlschema.Replace("\r\n", "\n"));
}
示例7: ReadWriteXmlSchema_Nested
public void ReadWriteXmlSchema_Nested()
{
DataSet ds = new DataSet("dataset");
ds.Tables.Add("table1");
ds.Tables.Add("table2");
ds.Tables[0].Columns.Add("col");
ds.Tables[1].Columns.Add("col");
ds.Relations.Add("rel", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0], true);
ds.Relations[0].Nested = true;
MemoryStream ms = new MemoryStream();
ds.WriteXmlSchema(ms);
DataSet ds1 = new DataSet();
ds1.ReadXmlSchema(new MemoryStream(ms.GetBuffer()));
// no new relation, and <table>_Id columns, should get created when
// Relation.Nested = true
Assert.Equal(1, ds1.Relations.Count);
Assert.Equal(1, ds1.Tables[0].Columns.Count);
Assert.Equal(1, ds1.Tables[1].Columns.Count);
}
示例8: ReadXmlSchema_ByFileName
public void ReadXmlSchema_ByFileName()
{
string sTempFileName = Path.Combine(Path.GetTempPath(), "tmpDataSet_ReadWriteXml_43899.xml");
DataSet ds1 = new DataSet();
ds1.Tables.Add(DataProvider.CreateParentDataTable());
ds1.Tables.Add(DataProvider.CreateChildDataTable());
//write xml file, schema only
ds1.WriteXmlSchema(sTempFileName);
//copy both data and schema
DataSet ds2 = new DataSet();
ds2.ReadXmlSchema(sTempFileName);
//check xml schema
// ReadXmlSchema - Tables count
Assert.Equal(ds2.Tables.Count, ds1.Tables.Count);
// ReadXmlSchema - Tables 0 Col count
Assert.Equal(ds1.Tables[0].Columns.Count, ds2.Tables[0].Columns.Count);
// ReadXmlSchema - Tables 1 Col count
Assert.Equal(ds1.Tables[1].Columns.Count, ds2.Tables[1].Columns.Count);
//check some colummns types
// ReadXmlSchema - Tables 0 Col type
Assert.Equal(ds1.Tables[0].Columns[0].GetType(), ds2.Tables[0].Columns[0].GetType());
// ReadXmlSchema - Tables 1 Col type
Assert.Equal(ds1.Tables[1].Columns[3].GetType(), ds2.Tables[1].Columns[3].GetType());
//check that no data exists
// ReadXmlSchema - Table 1 row count
Assert.Equal(0, ds2.Tables[0].Rows.Count);
// ReadXmlSchema - Table 2 row count
Assert.Equal(0, ds2.Tables[1].Rows.Count);
//try to delete the file
File.Delete(sTempFileName);
}
示例9: WriteXmlSchema_Relations_ForeignKeys
public void WriteXmlSchema_Relations_ForeignKeys()
{
MemoryStream ms = null;
MemoryStream ms1 = null;
DataSet ds1 = new DataSet();
DataTable table1 = ds1.Tables.Add("Table 1");
DataTable table2 = ds1.Tables.Add("Table 2");
DataColumn col1_1 = table1.Columns.Add("col 1", typeof(int));
DataColumn col1_2 = table1.Columns.Add("col 2", typeof(int));
DataColumn col1_3 = table1.Columns.Add("col 3", typeof(int));
DataColumn col1_4 = table1.Columns.Add("col 4", typeof(int));
DataColumn col1_5 = table1.Columns.Add("col 5", typeof(int));
DataColumn col1_6 = table1.Columns.Add("col 6", typeof(int));
DataColumn col1_7 = table1.Columns.Add("col 7", typeof(int));
DataColumn col2_1 = table2.Columns.Add("col 1", typeof(int));
DataColumn col2_2 = table2.Columns.Add("col 2", typeof(int));
DataColumn col2_3 = table2.Columns.Add("col 3", typeof(int));
DataColumn col2_4 = table2.Columns.Add("col 4", typeof(int));
DataColumn col2_5 = table2.Columns.Add("col 5", typeof(int));
DataColumn col2_6 = table2.Columns.Add("col 6", typeof(int));
ds1.Relations.Add("rel 1",
new DataColumn[] { col1_1, col1_2 },
new DataColumn[] { col2_1, col2_2 });
ds1.Relations.Add("rel 2",
new DataColumn[] { col1_3, col1_4 },
new DataColumn[] { col2_3, col2_4 },
false);
table1.Constraints.Add("pk 1", col1_7, true);
table2.Constraints.Add("fk 1",
new DataColumn[] { col1_5, col1_6 },
new DataColumn[] { col2_5, col2_6 });
ms = new MemoryStream();
ds1.WriteXmlSchema(ms);
ms1 = new MemoryStream(ms.GetBuffer());
DataSet ds2 = new DataSet();
ds2.ReadXmlSchema(ms1);
Assert.Equal(2, ds2.Relations.Count);
Assert.Equal(3, ds2.Tables[0].Constraints.Count);
Assert.Equal(2, ds2.Tables[1].Constraints.Count);
Assert.True(ds2.Relations.Contains("rel 1"));
Assert.True(ds2.Relations.Contains("rel 2"));
Assert.True(ds2.Tables[0].Constraints.Contains("pk 1"));
Assert.True(ds2.Tables[1].Constraints.Contains("fk 1"));
Assert.True(ds2.Tables[1].Constraints.Contains("rel 1"));
Assert.Equal(2, ds2.Relations["rel 1"].ParentColumns.Length);
Assert.Equal(2, ds2.Relations["rel 1"].ChildColumns.Length);
Assert.Equal(2, ds2.Relations["rel 2"].ParentColumns.Length);
Assert.Equal(2, ds2.Relations["rel 2"].ChildColumns.Length);
ForeignKeyConstraint fk = (ForeignKeyConstraint)ds2.Tables[1].Constraints["fk 1"];
Assert.Equal(2, fk.RelatedColumns.Length);
Assert.Equal(2, fk.Columns.Length);
}
示例10: WriteXmlSchema_ConstraintNameWithSpaces
public void WriteXmlSchema_ConstraintNameWithSpaces()
{
DataSet ds = new DataSet();
DataTable table1 = ds.Tables.Add("table1");
DataTable table2 = ds.Tables.Add("table2");
table1.Columns.Add("col1", typeof(int));
table2.Columns.Add("col1", typeof(int));
table1.Constraints.Add("uc 1", table1.Columns[0], false);
table2.Constraints.Add("fc 1", table1.Columns[0], table2.Columns[0]);
StringWriter sw = new StringWriter();
//should not throw an exception
ds.WriteXmlSchema(sw);
}
示例11: WriteXmlSchema_RelationAnnotation
public void WriteXmlSchema_RelationAnnotation()
{
DataSet ds1 = new DataSet();
DataTable table1 = ds1.Tables.Add();
DataTable table2 = ds1.Tables.Add();
DataColumn col1_1 = table1.Columns.Add("col1", typeof(int));
DataColumn col2_1 = table2.Columns.Add("col1", typeof(int));
ds1.Relations.Add("rel", col1_1, col2_1, false);
StringWriter sw = new StringWriter();
ds1.WriteXmlSchema(sw);
string xml = sw.ToString();
Assert.True(xml.IndexOf(@"<msdata:Relationship name=""rel"" msdata:parent=""Table1""" +
@" msdata:child=""Table2"" msdata:parentkey=""col1"" " +
@"msdata:childkey=""col1"" />") != -1, "#1");
}
示例12: WriteXmlSchema_ForignKeyConstraint
public void WriteXmlSchema_ForignKeyConstraint()
{
DataSet ds1 = new DataSet();
DataTable table1 = ds1.Tables.Add();
DataTable table2 = ds1.Tables.Add();
DataColumn col1_1 = table1.Columns.Add("col1", typeof(int));
DataColumn col2_1 = table2.Columns.Add("col1", typeof(int));
table2.Constraints.Add("fk", col1_1, col2_1);
StringWriter sw = new StringWriter();
ds1.WriteXmlSchema(sw);
string xml = sw.ToString();
Assert.True(xml.IndexOf(@"<xs:keyref name=""fk"" refer=""Constraint1"" " +
@"msdata:ConstraintOnly=""true"">") != -1, "#1");
}
示例13: ReadXmlSchema_ByXmlReader
public void ReadXmlSchema_ByXmlReader()
{
DataSet ds1 = new DataSet();
ds1.Tables.Add(DataProvider.CreateParentDataTable());
ds1.Tables.Add(DataProvider.CreateChildDataTable());
StringWriter sw = new StringWriter();
XmlTextWriter xmlTW = new XmlTextWriter(sw);
//write xml file, schema only
ds1.WriteXmlSchema(xmlTW);
xmlTW.Flush();
StringReader sr = new StringReader(sw.ToString());
XmlTextReader xmlTR = new XmlTextReader(sr);
//copy both data and schema
DataSet ds2 = new DataSet();
ds2.ReadXmlSchema(xmlTR);
//check xml schema
// ReadXmlSchema - Tables count
Assert.Equal(ds2.Tables.Count, ds1.Tables.Count);
// ReadXmlSchema - Tables 0 Col count
Assert.Equal(ds1.Tables[0].Columns.Count, ds2.Tables[0].Columns.Count);
// ReadXmlSchema - Tables 1 Col count
Assert.Equal(ds1.Tables[1].Columns.Count, ds2.Tables[1].Columns.Count);
//check some colummns types
// ReadXmlSchema - Tables 0 Col type
Assert.Equal(ds1.Tables[0].Columns[0].GetType(), ds2.Tables[0].Columns[0].GetType());
// ReadXmlSchema - Tables 1 Col type
Assert.Equal(ds1.Tables[1].Columns[3].GetType(), ds2.Tables[1].Columns[3].GetType());
//check that no data exists
// ReadXmlSchema - Table 1 row count
Assert.Equal(0, ds2.Tables[0].Rows.Count);
// ReadXmlSchema - Table 2 row count
Assert.Equal(0, ds2.Tables[1].Rows.Count);
}
示例14: OwnWriteXmlSchema
public void OwnWriteXmlSchema()
{
DataSet ds = new DataSet("test_dataset");
DataTable table = new DataTable("test_table");
DataColumn column = new DataColumn("first", typeof(string));
column.AllowDBNull = true;
column.DefaultValue = "test_default_value";
column.MaxLength = 100;
column.Caption = "test";
column.Unique = true;
table.Columns.Add(column);
DataColumn column2 = new DataColumn("second", typeof(SqlGuid));
column2.ColumnMapping = MappingType.Element;
table.Columns.Add(column2);
ds.Tables.Add(table);
DataTable table2 = new DataTable("second_test_table");
DataColumn column3 = new DataColumn("second_first", typeof(string));
column3.AllowDBNull = true;
column3.DefaultValue = "default_value";
column3.MaxLength = 100;
column3.Unique = true;
table2.Columns.Add(column3);
ds.Tables.Add(table2);
TextWriter writer = new StringWriter();
ds.WriteXmlSchema(writer);
string TextString = GetNormalizedSchema(writer.ToString());
// 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);
// This is original DataSet.WriteXmlSchema() output
// Assert.Equal ("<xs:schema id=\"test_dataset\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">", substring);
Assert.Equal("<xs:schema id=\"test_dataset\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
// This is original DataSet.WriteXmlSchema() output
// Assert.Equal (" <xs:element name=\"test_dataset\" msdata:IsDataSet=\"true\" msdata:Locale=\"fi-FI\">", substring);
Assert.Equal(" <xs:element msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\" name=\"test_dataset\">", 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 maxOccurs=\"unbounded\" minOccurs=\"0\">", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <xs:element name=\"test_table\">", 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);
// This is original DataSet.WriteXmlSchema() output
// Assert.Equal (" <xs:element name=\"first\" msdata:Caption=\"test\" default=\"test_default_value\" minOccurs=\"0\">", substring);
Assert.Equal(" <xs:element default=\"test_default_value\" minOccurs=\"0\" msdata:Caption=\"test\" name=\"first\">", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <xs:simpleType>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <xs:restriction base=\"xs:string\">", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <xs:maxLength value=\"100\" />", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </xs:restriction>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </xs:simpleType>", 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);
//.........这里部分代码省略.........
示例15: WriteXmlSchema2
public void WriteXmlSchema2()
{
string xml = @"<myDataSet xmlns='NetFrameWork'><myTable><id>0</id><item>item 0</item></myTable><myTable><id>1</id><item>item 1</item></myTable><myTable><id>2</id><item>item 2</item></myTable><myTable><id>3</id><item>item 3</item></myTable><myTable><id>4</id><item>item 4</item></myTable><myTable><id>5</id><item>item 5</item></myTable><myTable><id>6</id><item>item 6</item></myTable><myTable><id>7</id><item>item 7</item></myTable><myTable><id>8</id><item>item 8</item></myTable><myTable><id>9</id><item>item 9</item></myTable></myDataSet>";
string schema = @"<?xml version='1.0' encoding='utf-16'?>
<xs:schema id='myDataSet' targetNamespace='NetFrameWork' xmlns:mstns='NetFrameWork' xmlns='NetFrameWork' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' attributeFormDefault='qualified' elementFormDefault='qualified'>
<xs:element name='myDataSet' msdata:IsDataSet='true' " +
"msdata:UseCurrentLocale='true'"
+ @">
<xs:complexType>
<xs:choice minOccurs='0' maxOccurs='unbounded'>
<xs:element name='myTable'>
<xs:complexType>
<xs:sequence>
<xs:element name='id' msdata:AutoIncrement='true' type='xs:int' minOccurs='0' />
<xs:element name='item' type='xs:string' minOccurs='0' />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
DataSet OriginalDataSet = new DataSet("myDataSet");
OriginalDataSet.Namespace = "NetFrameWork";
DataTable myTable = new DataTable("myTable");
DataColumn c1 = new DataColumn("id", typeof(int));
c1.AutoIncrement = true;
DataColumn c2 = new DataColumn("item");
myTable.Columns.Add(c1);
myTable.Columns.Add(c2);
OriginalDataSet.Tables.Add(myTable);
// Add ten rows.
DataRow newRow;
for (int i = 0; i < 10; i++)
{
newRow = myTable.NewRow();
newRow["item"] = "item " + i;
myTable.Rows.Add(newRow);
}
OriginalDataSet.AcceptChanges();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.QuoteChar = '\'';
OriginalDataSet.WriteXml(xtw);
string result = sw.ToString();
Assert.Equal(xml, result);
sw = new StringWriter();
xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
OriginalDataSet.WriteXmlSchema(xtw);
result = sw.ToString();
result = result.Replace("\r\n", "\n").Replace('"', '\'');
Assert.Equal(schema.Replace("\r\n", "\n"), result);
}