本文整理汇总了C#中System.Data.DataSet.InferXmlSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.InferXmlSchema方法的具体用法?C# DataSet.InferXmlSchema怎么用?C# DataSet.InferXmlSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataSet
的用法示例。
在下文中一共展示了DataSet.InferXmlSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main (string [] args)
{
if (args.Length == 0) {
Console.WriteLine ("usage: mono xmldatareader.exe filename");
return;
}
Console.WriteLine ("Target file: " + args [0]);
DataSet ds = new DataSet ();
// ds.InferXmlSchema (args [0], null);
try {
ds.ReadXml (args [0]);
} catch (Exception ex) {
Console.WriteLine ("ReadXml() borked: " + ex.Message);
return;
}
Console.WriteLine ("---- DataSet ----------------");
StringWriter sw = new StringWriter ();
PrintDataSet (ds, sw);
PrintDataSet (ds, Console.Out);
ds = new DataSet ();
ds.InferXmlSchema (args [0], null);
XmlDataReader.ReadXml (ds, new XmlTextReader (args [0]));
Console.WriteLine ("---- XmlDataReader ----------------");
StringWriter sw2 = new StringWriter ();
PrintDataSet (ds, sw2);
if (sw.ToString () == sw2.ToString ())
Console.WriteLine ("Successful.");
else
Console.WriteLine ("Different *************************************************\n" + sw2);
}
示例2: 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);
}
示例3: Main
static void Main()
{
DataSet dataSet = new DataSet();
string[] ignoreNamesapces = {
"http://www.shop.com/pml",
"http://www.shop.com/cml"
};
dataSet.InferXmlSchema(@"..\..\ch13\orderlist.xml", ignoreNamesapces);
DisplaySchema.displayDataSetSchema(dataSet);
}
示例4: InferXmlSchema_inferingTables4
[Test] 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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream,null);
Assert.AreEqual("DocumentElement", ds.DataSetName, "DS84");
Assert.AreEqual("Element1", ds.Tables[0].TableName, "DS85");
Assert.AreEqual(1, ds.Tables.Count, "DS86");
Assert.AreEqual("attr1", ds.Tables[0].Columns["attr1"].ColumnName, "DS87");
Assert.AreEqual("attr2", ds.Tables[0].Columns["attr2"].ColumnName, "DS88");
}
示例5: 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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream,null);
Assert.AreEqual("DocumentElement", ds.DataSetName, "DS89");
Assert.AreEqual("Element1", ds.Tables[0].TableName, "DS90");
Assert.AreEqual(1, ds.Tables.Count, "DS91");
Assert.AreEqual("Element1_Text", ds.Tables[0].Columns["Element1_Text"].ColumnName, "DS92");
}
示例6: test5
public void test5()
{
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()));
DataSet ds = new DataSet();
// ds.ReadXml(myStream);
ds.InferXmlSchema(myStream, new string[] {"urn:schemas-microsoft-com:officedata"});
Compare(ds.Tables.Count,3);
Compare(ds.Tables[0].Columns.Count,3);
Compare(ds.Tables[0].Columns["CategoryID"].ColumnName,"CategoryID");
Compare(ds.Tables[0].Columns["Categories_Id"].ColumnName,"Categories_Id");//Hidden
Compare(ds.Tables[0].Columns["Description"].ColumnName,"Description");
Compare(ds.Tables[1].Columns.Count,3);
Compare(ds.Tables[1].Columns["adotype"].ColumnName,"adotype");
Compare(ds.Tables[1].Columns["CategoryName_Text"].ColumnName,"CategoryName_Text");
Compare(ds.Tables[1].Columns["Categories_Id"].ColumnName,"Categories_Id");//Hidden
Compare(ds.Tables[2].Columns.Count,3);
Compare(ds.Tables[2].Columns["ProductID"].ColumnName,"ProductID");
Compare(ds.Tables[2].Columns["ReorderLevel"].ColumnName,"ReorderLevel");
Compare(ds.Tables[2].Columns["Discontinued"].ColumnName,"Discontinued");
}
示例7: InferXmlSchema_inferingTables2
[Test] public void InferXmlSchema_inferingTables2()
{
//Acroding to the msdn documantaion :
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringtables.htm
//Elements that have child elements will result in inferred tables
// inferingTables2
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1>");
sb.Append("<ChildElement1>Text1</ChildElement1>");
sb.Append("</Element1>");
sb.Append("</DocumentElement>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream,null);
Assert.AreEqual("DocumentElement", ds.DataSetName, "DS75");
Assert.AreEqual("Element1", ds.Tables[0].TableName, "DS76");
Assert.AreEqual(1, ds.Tables.Count, "DS77");
Assert.AreEqual("ChildElement1", ds.Tables[0].Columns["ChildElement1"].ColumnName, "DS78");
}
示例8: InferXmlSchema_elementText2
[Test] 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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream,null);
Assert.AreEqual("DocumentElement", ds.DataSetName, "DS149");
Assert.AreEqual("Element1", ds.Tables[0].TableName, "DS150");
Assert.AreEqual(1, ds.Tables.Count, "DS151");
Assert.AreEqual("ChildElement1", ds.Tables["Element1"].Columns["ChildElement1"].ColumnName, "DS152");
Assert.AreEqual(MappingType.Element, ds.Tables["Element1"].Columns["ChildElement1"].ColumnMapping , "DS153");
Assert.AreEqual(typeof(string), ds.Tables["Element1"].Columns["ChildElement1"].DataType , "DS154");
Assert.AreEqual(1, ds.Tables["Element1"].Columns.Count, "DS155");
}
示例9: inferingTables4
public void 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
BeginCase("inferingTables4");
Exception exp=null;
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1 attr1='value1' attr2='value2'/>");
sb.Append("</DocumentElement>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
try
{
ds.InferXmlSchema(myStream,null);
Compare(ds.DataSetName,"DocumentElement");
Compare(ds.Tables[0].TableName,"Element1");
Compare(ds.Tables.Count,1);
Compare(ds.Tables[0].Columns["attr1"].ColumnName,"attr1");
Compare(ds.Tables[0].Columns["attr2"].ColumnName,"attr2");
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
示例10: Run
//.........这里部分代码省略.........
else if (option == "nologo")
{
// ignore, since we do not output a logo anyway
}
else
Error (unknownOption, option);
}
if (!schemasOptions && !assemblyOptions && !inference)
Error (invalidParams);
if (schemasOptions && assemblyOptions)
Error (incompatibleArgs);
if (assemblies.Count > 1)
Error (tooManyAssem);
if (outputDir == null) outputDir = ".";
string typename = null;
Type generatorType = null;
if (language != null) {
switch (language) {
case "CS":
provider = new CSharpCodeProvider ();
break;
case "VB":
provider = new VBCodeProvider ();
break;
default:
typename = StripQuot (language);
generatorType = Type.GetType (typename);
if (generatorType == null)
Error (generatorTypeNotFound, typename);
break;
}
}
if (providerOption != null) {
string param = providerOption;
int comma = param.IndexOf (',');
if (comma < 0) {
typename = StripQuot (param);
generatorType = Type.GetType (param);
} else {
typename = param.Substring (0, comma);
string asmName = param.Substring (comma + 1);
#if NET_1_1
Assembly asm = Assembly.LoadFile (asmName);
#else
Assembly asm = Assembly.LoadFrom (asmName);
#endif
if (asm == null)
Error (generatorAssemblyNotFound, asmName);
generatorType = asm.GetType (typename);
}
if (generatorType == null)
Error (generatorTypeNotFound, typename);
}
if (generatorType != null) {
if (!generatorType.IsSubclassOf (typeof (CodeDomProvider)))
Error (generatorTypeIsNotCodeGenerator, typename);
try {
provider = (CodeDomProvider) Activator.CreateInstance (generatorType, null);
} catch (Exception ex) {
Error (generatorThrewException, generatorType.AssemblyQualifiedName.ToString () + " --> " + ex.Message);
}
Console.WriteLine ("Loaded custom generator type " + generatorType + " .");
}
if (provider == null)
provider = new CSharpCodeProvider ();
if (schemasOptions)
{
if (!generateClasses && !generateDataset)
Error (missingOutputForXsdInput);
schemaNames.AddRange (unknownFiles);
if (generateClasses)
GenerateClasses ();
else if (generateDataset)
GenerateDataset ();
}
else if (inference)
{
foreach (string xmlfile in inferenceNames) {
string genFile = Path.Combine (outputDir, Path.GetFileNameWithoutExtension (xmlfile) + ".xsd");
DataSet ds = new DataSet ();
ds.InferXmlSchema (xmlfile, null);
ds.WriteXmlSchema (genFile);
Console.WriteLine ("Written file " + genFile);
}
}
else
{
assemblies.AddRange (unknownFiles);
GenerateSchemas ();
}
}
示例11: InferXmlSchema_inferringRelationships1
[Test] 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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
ds.InferXmlSchema(myStream,null);
Assert.AreEqual("DocumentElement", ds.DataSetName, "DS111");
Assert.AreEqual("Element1", ds.Tables[0].TableName, "DS112");
Assert.AreEqual("ChildElement1", ds.Tables[1].TableName, "DS113");
Assert.AreEqual(2, ds.Tables.Count, "DS114");
Assert.AreEqual("Element1_Id", ds.Tables["Element1"].Columns["Element1_Id"].ColumnName, "DS115");
Assert.AreEqual(MappingType.Hidden, ds.Tables["Element1"].Columns["Element1_Id"].ColumnMapping , "DS116");
Assert.AreEqual(typeof(Int32), ds.Tables["Element1"].Columns["Element1_Id"].DataType , "DS117");
Assert.AreEqual("ChildElement2", ds.Tables["Element1"].Columns["ChildElement2"].ColumnName, "DS118");
Assert.AreEqual(MappingType.Element, ds.Tables["Element1"].Columns["ChildElement2"].ColumnMapping , "DS119");
Assert.AreEqual(typeof(string), ds.Tables["Element1"].Columns["ChildElement2"].DataType , "DS120");
Assert.AreEqual("attr1", ds.Tables["ChildElement1"].Columns["attr1"].ColumnName, "DS121");
Assert.AreEqual(MappingType.Attribute, ds.Tables["ChildElement1"].Columns["attr1"].ColumnMapping , "DS122");
Assert.AreEqual(typeof(string), ds.Tables["ChildElement1"].Columns["attr1"].DataType , "DS123");
Assert.AreEqual("attr2", ds.Tables["ChildElement1"].Columns["attr2"].ColumnName, "DS124");
Assert.AreEqual(MappingType.Attribute, ds.Tables["ChildElement1"].Columns["attr2"].ColumnMapping , "DS125");
Assert.AreEqual(typeof(string), ds.Tables["ChildElement1"].Columns["attr2"].DataType , "DS126");
Assert.AreEqual("Element1_Id", ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnName, "DS127");
Assert.AreEqual(MappingType.Hidden, ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnMapping , "DS128");
Assert.AreEqual(typeof(Int32), ds.Tables["ChildElement1"].Columns["Element1_Id"].DataType , "DS129");
//Checking dataRelation :
Assert.AreEqual("Element1", ds.Relations["Element1_ChildElement1"].ParentTable.TableName, "DS130");
Assert.AreEqual("Element1_Id", ds.Relations["Element1_ChildElement1"].ParentColumns[0].ColumnName, "DS131");
Assert.AreEqual("ChildElement1", ds.Relations["Element1_ChildElement1"].ChildTable.TableName, "DS132");
Assert.AreEqual("Element1_Id", ds.Relations["Element1_ChildElement1"].ChildColumns[0].ColumnName, "DS133");
Assert.AreEqual(true, ds.Relations["Element1_ChildElement1"].Nested, "DS134");
//Checking ForeignKeyConstraint
ForeignKeyConstraint con = (ForeignKeyConstraint)ds.Tables["ChildElement1"].Constraints["Element1_ChildElement1"];
Assert.AreEqual("Element1_Id", con.Columns[0].ColumnName, "DS135");
Assert.AreEqual(Rule.Cascade, con.DeleteRule, "DS136");
Assert.AreEqual(AcceptRejectRule.None, con.AcceptRejectRule, "DS137");
Assert.AreEqual("Element1", con.RelatedTable.TableName, "DS138");
Assert.AreEqual("ChildElement1", con.Table.TableName, "DS139");
}
示例12: inferringRelationships1
public void inferringRelationships1()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringrelationships.htm
BeginCase("inferringRelationships1");
Exception exp=null;
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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
try
{
ds.InferXmlSchema(myStream,null);
Compare(ds.DataSetName,"DocumentElement");
Compare(ds.Tables[0].TableName,"Element1");
Compare(ds.Tables[1].TableName,"ChildElement1");
Compare(ds.Tables.Count,2);
Compare(ds.Tables["Element1"].Columns["Element1_Id"].ColumnName,"Element1_Id");
Compare(ds.Tables["Element1"].Columns["Element1_Id"].ColumnMapping ,MappingType.Hidden);
Compare(ds.Tables["Element1"].Columns["Element1_Id"].DataType ,typeof(Int32));
Compare(ds.Tables["Element1"].Columns["ChildElement2"].ColumnName,"ChildElement2");
Compare(ds.Tables["Element1"].Columns["ChildElement2"].ColumnMapping ,MappingType.Element);
Compare(ds.Tables["Element1"].Columns["ChildElement2"].DataType ,typeof(string));
Compare(ds.Tables["ChildElement1"].Columns["attr1"].ColumnName,"attr1");
Compare(ds.Tables["ChildElement1"].Columns["attr1"].ColumnMapping ,MappingType.Attribute);
Compare(ds.Tables["ChildElement1"].Columns["attr1"].DataType ,typeof(string));
Compare(ds.Tables["ChildElement1"].Columns["attr2"].ColumnName,"attr2");
Compare(ds.Tables["ChildElement1"].Columns["attr2"].ColumnMapping ,MappingType.Attribute);
Compare(ds.Tables["ChildElement1"].Columns["attr2"].DataType ,typeof(string));
Compare(ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnName,"Element1_Id");
Compare(ds.Tables["ChildElement1"].Columns["Element1_Id"].ColumnMapping ,MappingType.Hidden);
Compare(ds.Tables["ChildElement1"].Columns["Element1_Id"].DataType ,typeof(Int32));
//Checking dataRelation :
Compare(ds.Relations["Element1_ChildElement1"].ParentTable.TableName,"Element1");
Compare(ds.Relations["Element1_ChildElement1"].ParentColumns[0].ColumnName,"Element1_Id");
Compare(ds.Relations["Element1_ChildElement1"].ChildTable.TableName,"ChildElement1");
Compare(ds.Relations["Element1_ChildElement1"].ChildColumns[0].ColumnName,"Element1_Id");
Compare(ds.Relations["Element1_ChildElement1"].Nested,true);
//Checking ForeignKeyConstraint
ForeignKeyConstraint con = (ForeignKeyConstraint)ds.Tables["ChildElement1"].Constraints["Element1_ChildElement1"];
Compare(con.Columns[0].ColumnName,"Element1_Id");
Compare(con.DeleteRule,Rule.Cascade);
Compare(con.AcceptRejectRule,AcceptRejectRule.None);
Compare(con.RelatedTable.TableName,"Element1");
Compare(con.Table.TableName,"ChildElement1");
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
示例13: elementText2
public void elementText2()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringelementtext.htm
BeginCase("elementText1");
Exception exp=null;
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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
try
{
ds.InferXmlSchema(myStream,null);
Compare(ds.DataSetName,"DocumentElement");
Compare(ds.Tables[0].TableName,"Element1");
Compare(ds.Tables.Count,1);
Compare(ds.Tables["Element1"].Columns["ChildElement1"].ColumnName,"ChildElement1");
Compare(ds.Tables["Element1"].Columns["ChildElement1"].ColumnMapping ,MappingType.Element);
Compare(ds.Tables["Element1"].Columns["ChildElement1"].DataType ,typeof(string));
Compare(ds.Tables["Element1"].Columns.Count,1);
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
示例14: inferringColumns2
public void 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
BeginCase("inferringColumns2");
Exception exp=null;
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>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
try
{
ds.InferXmlSchema(myStream,null);
Compare(ds.DataSetName,"DocumentElement");
Compare(ds.Tables[0].TableName,"Element1");
Compare(ds.Tables.Count,1);
Compare(ds.Tables[0].Columns["ChildElement1"].ColumnName,"ChildElement1");
Compare(ds.Tables[0].Columns["ChildElement2"].ColumnName,"ChildElement2");
Compare(ds.Tables[0].Columns["ChildElement1"].ColumnMapping ,MappingType.Element);
Compare(ds.Tables[0].Columns["ChildElement2"].ColumnMapping ,MappingType.Element);
Compare(ds.Tables[0].Columns["ChildElement1"].DataType ,typeof(string));
Compare(ds.Tables[0].Columns["ChildElement2"].DataType ,typeof(string));
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}
示例15: inferringColumns1
public void inferringColumns1()
{
//ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconinferringcolumns.htm
BeginCase("inferringColumns1");
Exception exp=null;
StringBuilder sb = new StringBuilder();
sb.Append("<DocumentElement>");
sb.Append("<Element1 attr1='value1' attr2='value2'/>");
sb.Append("</DocumentElement>");
DataSet ds = new DataSet();
MemoryStream myStream = new MemoryStream(new ASCIIEncoding().GetBytes(sb.ToString()));
try
{
ds.InferXmlSchema(myStream,null);
Compare(ds.DataSetName,"DocumentElement");
Compare(ds.Tables[0].TableName,"Element1");
Compare(ds.Tables.Count,1);
Compare(ds.Tables[0].Columns["attr1"].ColumnName,"attr1");
Compare(ds.Tables[0].Columns["attr2"].ColumnName,"attr2");
Compare(ds.Tables[0].Columns["attr1"].ColumnMapping ,MappingType.Attribute);
Compare(ds.Tables[0].Columns["attr2"].ColumnMapping ,MappingType.Attribute);
Compare(ds.Tables[0].Columns["attr1"].DataType ,typeof(string));
Compare(ds.Tables[0].Columns["attr2"].DataType ,typeof(string));
}
catch (Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
}
}