本文整理汇总了C#中DataSet.InferXmlSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.InferXmlSchema方法的具体用法?C# DataSet.InferXmlSchema怎么用?C# DataSet.InferXmlSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.InferXmlSchema方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SignificantWhitespaceIgnored2
public void SignificantWhitespaceIgnored2()
{
// To make sure, create pure significant whitespace element
// using XmlNodeReader (that does not have xml:space attribute
// column).
DataSet ds = new DataSet();
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("root"));
doc.DocumentElement.AppendChild(doc.CreateSignificantWhitespace
(" \n\n"));
XmlReader xr = new XmlNodeReader(doc);
ds.InferXmlSchema(xr, null);
AssertDataSet("pure_whitespace", ds, "root", 0, 0);
}
示例2: IgnoredNamespaces
public void IgnoredNamespaces()
{
string xml = "<root attr='val' xmlns:a='urn:foo' a:foo='hogehoge' />";
DataSet ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml), null);
AssertDataSet("ds", ds, "NewDataSet", 1, 0);
AssertDataTable("dt", ds.Tables[0], "root", 2, 0, 0, 0, 0, 0);
ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml), new string[] { "urn:foo" });
AssertDataSet("ds", ds, "NewDataSet", 1, 0);
// a:foo is ignored
AssertDataTable("dt", ds.Tables[0], "root", 1, 0, 0, 0, 0, 0);
}
示例3: GetDataSet
/*
// simple diffgram
string xml23 = @"<set>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='table'>
<xs:complexType>
<xs:choice>
<xs:any />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram
xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'
xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
<table>
<col>1</col>
</table>
</diffgr:diffgram>
</set>";
// just deep table
string xml24 = "<p1><p2><p3><p4><p5><p6/></p5></p4></p3></p2></p1>";
*/
private DataSet GetDataSet(string xml, string[] nss)
{
DataSet ds = new DataSet();
ds.InferXmlSchema(new XmlTextReader(xml, XmlNodeType.Document, null), nss);
return ds;
}
示例4: NullFileName
public void NullFileName()
{
DataSet ds = new DataSet();
ds.InferXmlSchema((XmlReader)null, null);
AssertDataSet("null", ds, "NewDataSet", 0, 0);
}
示例5: InferXmlSchema_elementText2
public void InferXmlSchema_elementText2()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringelementtext.htm
// elementText1
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1>");
sb.Append("Text1");
sb.Append("<ChildElement1>Text2</ChildElement1>");
sb.Append("Text3");
sb.Append("</Element1>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal(1, ds.Tables.Count);
Assert.Equal("ChildElement1", ds.Tables["Element1"].Columns["ChildElement1"].ColumnName);
Assert.Equal(MappingType.Element, ds.Tables["Element1"].Columns["ChildElement1"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables["Element1"].Columns["ChildElement1"].DataType);
Assert.Equal(1, ds.Tables["Element1"].Columns.Count);
}
示例6: SimpleLoad
public void SimpleLoad()
{
string xml001 = "<root/>";
XmlDataDocument doc = new XmlDataDocument();
DataSet ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml001), null);
doc.LoadXml(xml001);
string xml002 = "<root><child/></root>";
doc = new XmlDataDocument();
ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml002), null);
doc.LoadXml(xml002);
string xml003 = "<root><col1>test</col1><col1></col1></root>";
doc = new XmlDataDocument();
ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml003), null);
doc.LoadXml(xml003);
string xml004 = "<set><tab1><col1>test</col1><col1>test2</col1></tab1><tab2><col2>test3</col2><col2>test4</col2></tab2></set>";
doc = new XmlDataDocument();
ds = new DataSet();
ds.InferXmlSchema(new StringReader(xml004), null);
doc.LoadXml(xml004);
}
示例7: InferXmlSchema_inferringColumns2
public void InferXmlSchema_inferringColumns2()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringcolumns.htm
//If an element has no child elements or attributes, it will be inferred as a column.
//The ColumnMapping property of the column will be set to MappingType.Element.
//The text for child elements is stored in a row in the table
// inferringColumns2
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1>");
sb.Append("<ChildElement1>Text1</ChildElement1>");
sb.Append("<ChildElement2>Text2</ChildElement2>");
sb.Append("</Element1>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal(1, ds.Tables.Count);
Assert.Equal("ChildElement1", ds.Tables[0].Columns["ChildElement1"].ColumnName);
Assert.Equal("ChildElement2", ds.Tables[0].Columns["ChildElement2"].ColumnName);
Assert.Equal(MappingType.Element, ds.Tables[0].Columns["ChildElement1"].ColumnMapping);
Assert.Equal(MappingType.Element, ds.Tables[0].Columns["ChildElement2"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables[0].Columns["ChildElement1"].DataType);
Assert.Equal(typeof(string), ds.Tables[0].Columns["ChildElement2"].DataType);
}
示例8: InferXmlSchema_inferringRelationships1
public void InferXmlSchema_inferringRelationships1()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringrelationships.htm
// inferringRelationships1
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1>");
sb.Append("<ChildElement1 attr1='value1' attr2='value2'/>");
sb.Append("<ChildElement2>Text2</ChildElement2>");
sb.Append("</Element1>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal("ChildElement1", ds.Tables[1].TableName);
Assert.Equal(2, ds.Tables.Count);
Assert.Equal("Element1_Id", ds.Tables["Element1"].Columns["Element1_Id"].ColumnName);
Assert.Equal(MappingType.Hidden, ds.Tables["Element1"].Columns["Element1_Id"].ColumnMapping);
Assert.Equal(typeof(int), ds.Tables["Element1"].Columns["Element1_Id"].DataType);
Assert.Equal("ChildElement2", ds.Tables["Element1"].Columns["ChildElement2"].ColumnName);
Assert.Equal(MappingType.Element, ds.Tables["Element1"].Columns["ChildElement2"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables["Element1"].Columns["ChildElement2"].DataType);
Assert.Equal("attr1", ds.Tables["ChildElement1"].Columns["attr1"].ColumnName);
Assert.Equal(MappingType.Attribute, ds.Tables["ChildElement1"].Columns["attr1"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables["ChildElement1"].Columns["attr1"].DataType);
Assert.Equal("attr2", ds.Tables["ChildElement1"].Columns["attr2"].ColumnName);
Assert.Equal(MappingType.Attribute, ds.Tables["ChildElement1"].Columns["attr2"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables["ChildElement1"].Columns["attr2"].DataType);
Assert.Equal("Element1_Id", ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnName);
Assert.Equal(MappingType.Hidden, ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnMapping);
Assert.Equal(typeof(int), ds.Tables["ChildElement1"].Columns["Element1_Id"].DataType);
//Checking dataRelation :
Assert.Equal("Element1", ds.Relations["Element1_ChildElement1"].ParentTable.TableName);
Assert.Equal("Element1_Id", ds.Relations["Element1_ChildElement1"].ParentColumns[0].ColumnName);
Assert.Equal("ChildElement1", ds.Relations["Element1_ChildElement1"].ChildTable.TableName);
Assert.Equal("Element1_Id", ds.Relations["Element1_ChildElement1"].ChildColumns[0].ColumnName);
Assert.Equal(true, ds.Relations["Element1_ChildElement1"].Nested);
//Checking ForeignKeyConstraint
ForeignKeyConstraint con = (ForeignKeyConstraint)ds.Tables["ChildElement1"].Constraints["Element1_ChildElement1"];
Assert.Equal("Element1_Id", con.Columns[0].ColumnName);
Assert.Equal(Rule.Cascade, con.DeleteRule);
Assert.Equal(AcceptRejectRule.None, con.AcceptRejectRule);
Assert.Equal("Element1", con.RelatedTable.TableName);
Assert.Equal("ChildElement1", con.Table.TableName);
}
示例9: InferXmlSchema_inferringColumns1
public void InferXmlSchema_inferringColumns1()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringcolumns.htm
// inferringColumns1
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1 attr1='value1' attr2='value2'/>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal(1, ds.Tables.Count);
Assert.Equal("attr1", ds.Tables[0].Columns["attr1"].ColumnName);
Assert.Equal("attr2", ds.Tables[0].Columns["attr2"].ColumnName);
Assert.Equal(MappingType.Attribute, ds.Tables[0].Columns["attr1"].ColumnMapping);
Assert.Equal(MappingType.Attribute, ds.Tables[0].Columns["attr2"].ColumnMapping);
Assert.Equal(typeof(string), ds.Tables[0].Columns["attr1"].DataType);
Assert.Equal(typeof(string), ds.Tables[0].Columns["attr2"].DataType);
}
示例10: InferXmlSchema_inferingTables5
public void InferXmlSchema_inferingTables5()
{
//Acroding to the msdn documantaion :
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringtables.htm
//Elements that repeat will result in a single inferred table
// inferingTables5
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1>Text1</Element1>");
sb.Append("<Element1>Text2</Element1>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal(1, ds.Tables.Count);
Assert.Equal("Element1_Text", ds.Tables[0].Columns["Element1_Text"].ColumnName);
}
示例11: InferXmlSchema_inferingTables4
public void InferXmlSchema_inferingTables4()
{
//Acroding to the msdn documantaion :
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringtables.htm
//The document, or root, element will result in an inferred table if it has attributes
//or child elements that will be inferred as columns.
//If the document element has no attributes and no child elements that would be inferred as columns, the element will be inferred as a DataSet
// inferingTables4
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1 attr1='value1' attr2='value2'/>");
sb.Append("</DocumentElement>");
var ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream, null);
Assert.Equal("DocumentElement", ds.DataSetName);
Assert.Equal("Element1", ds.Tables[0].TableName);
Assert.Equal(1, ds.Tables.Count);
Assert.Equal("attr1", ds.Tables[0].Columns["attr1"].ColumnName);
Assert.Equal("attr2", ds.Tables[0].Columns["attr2"].ColumnName);
}
示例12: InferXmlSchema_IgnoreNameSpaces
public void InferXmlSchema_IgnoreNameSpaces() //Ignoring 2 namespaces
{
StringBuilder sb = new StringBuilder();
sb.Append("<h:html xmlns:xdc='http://www.xml.com/books' xmlns:h='http://www.w3.org/HTML/1998/html4'>");
sb.Append("<h:head><h:title>Book Review</h:title></h:head>");
sb.Append("<h:body>");
sb.Append("<xdc:bookreview>");
sb.Append("<xdc:title h:attrib1='1' xdc:attrib2='2' >XML: A Primer</xdc:title>");
sb.Append("</xdc:bookreview>");
sb.Append("</h:body>");
sb.Append("</h:html>");
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
DataSet tempDs = new DataSet();
tempDs.ReadXml(myStream);
myStream.Seek(0, SeekOrigin.Begin);
var ds = new DataSet();
ds.InferXmlSchema(myStream, new string[] { "http://www.xml.com/books", "http://www.w3.org/HTML/1998/html4" });
//Assert.Equal(8, ds.Tables.Count);
// string str1 = tempDs.GetXmlSchema(); //DataProvider.GetDSSchema(tempDs);
// string str2 = ds.GetXmlSchema(); //DataProvider.GetDSSchema(ds);
Assert.Equal(3, ds.Tables.Count);
Assert.Equal("bookreview", ds.Tables[2].TableName);
Assert.Equal(2, ds.Tables[2].Columns.Count);
}
示例13: InferXmlSchema_IgnoreNameSpace
public void InferXmlSchema_IgnoreNameSpace()
{
StringBuilder sb = new StringBuilder();
sb.Append("<NewDataSet xmlns:od='urn:schemas-microsoft-com:officedata'>");
sb.Append("<Categories>");
sb.Append("<CategoryID od:adotype='3'>1</CategoryID>");
sb.Append("<CategoryName od:maxLength='15' adotype='130'>Beverages</CategoryName>");
sb.Append("<Description od:adotype='203'>Soft drinks and teas</Description>");
sb.Append("</Categories>");
sb.Append("<Products>");
sb.Append("<ProductID od:adotype='20'>1</ProductID>");
sb.Append("<ReorderLevel od:adotype='3'>10</ReorderLevel>");
sb.Append("<Discontinued od:adotype='11'>0</Discontinued>");
sb.Append("</Products>");
sb.Append("</NewDataSet>");
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
var ds = new DataSet();
// ds.ReadXml(myStream);
ds.InferXmlSchema(myStream, new string[] { "urn:schemas-microsoft-com:officedata" });
Assert.Equal(3, ds.Tables.Count);
Assert.Equal(3, ds.Tables[0].Columns.Count);
Assert.Equal("CategoryID", ds.Tables[0].Columns["CategoryID"].ColumnName);
Assert.Equal("Categories_Id", ds.Tables[0].Columns["Categories_Id"].ColumnName);
Assert.Equal("Description", ds.Tables[0].Columns["Description"].ColumnName);
Assert.Equal(3, ds.Tables[1].Columns.Count);
Assert.Equal("adotype", ds.Tables[1].Columns["adotype"].ColumnName);
Assert.Equal("CategoryName_Text", ds.Tables[1].Columns["CategoryName_Text"].ColumnName);
Assert.Equal("Categories_Id", ds.Tables[1].Columns["Categories_Id"].ColumnName);
Assert.Equal(3, ds.Tables[2].Columns.Count);
Assert.Equal("ProductID", ds.Tables[2].Columns["ProductID"].ColumnName);
Assert.Equal("ReorderLevel", ds.Tables[2].Columns["ReorderLevel"].ColumnName);
Assert.Equal("Discontinued", ds.Tables[2].Columns["Discontinued"].ColumnName);
}