本文整理汇总了C#中DataSet.ReadXml方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.ReadXml方法的具体用法?C# DataSet.ReadXml怎么用?C# DataSet.ReadXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.ReadXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFeed
public static List<RssFeedItem> ReadFeed(string url)
{
//create a new list of the rss feed items to return
List<RssFeedItem> rssFeedItems = new List<RssFeedItem>();
//create an http request which will be used to retrieve the rss feed
HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(url);
//use a dataset to retrieve the rss feed
using (DataSet rssData = new DataSet())
{
//read the xml from the stream of the web request
rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());
//loop through the rss items in the dataset and populate the list of rss feed items
foreach (DataRow dataRow in rssData.Tables["item"].Rows)
{
rssFeedItems.Add(new RssFeedItem
{
ChannelId = Convert.ToInt32(dataRow["channel_Id"]),
Description = Convert.ToString(dataRow["description"]),
ItemId = Convert.ToInt32(dataRow["item_Id"]),
Link = Convert.ToString(dataRow["link"]),
PublishDate = Convert.ToDateTime(dataRow["pubDate"]),
Title = Convert.ToString(dataRow["title"])
});
}
}
//return the rss feed items
return rssFeedItems;
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var ds = new DataSet();
ds.ReadXml(StrXml);
ReportViewer1.DataBind();
}
示例3: ConflictExistingPrimaryKey
public void ConflictExistingPrimaryKey()
{
Assert.Throws<ConstraintException>(() =>
{
// <wrong>The 'col' DataTable tries to create another primary key (and fails)</wrong> The data violates key constraint.
var ds = new DataSet();
ds.Tables.Add(new DataTable("table"));
DataColumn c = new DataColumn("pk");
ds.Tables[0].Columns.Add(c);
ds.Tables[0].PrimaryKey = new DataColumn[] { c };
XmlTextReader xtr = new XmlTextReader(_xml22, XmlNodeType.Document, null);
xtr.Read();
ds.ReadXml(xtr, XmlReadMode.InferSchema);
});
}
示例4: XmlLoadCustomTypesTest
public void XmlLoadCustomTypesTest()
{
string xml = "<CustomTypesData>" + Environment.NewLine +
"<CustomTypesTable>" + Environment.NewLine +
"<Dummy>99</Dummy>" + Environment.NewLine +
"<FuncXml> " + Environment.NewLine +
"<Func Name=\"CUT_IntPassiveIn()\" Direction=\"PASSIVE_MOCK\">" + Environment.NewLine +
"<Param Name=\"paramLen\" Type=\"int\" Len=\"1\" InOut=\"IN\" Union=\"FALSE\" " + Environment.NewLine +
"Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"1\" IsExpGetRef=\"\" " + Environment.NewLine +
"IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" HandleInput=\"DEC\" " + Environment.NewLine +
"Enum=\"\">" + Environment.NewLine +
"</Param>" + Environment.NewLine + Environment.NewLine +
"<Param Name=\"single\" Type=\"int\" Len=\"1\" InOut=\"IN\" Union=\"FALSE\" " + Environment.NewLine +
"Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"16\" IsExpGetRef=\"\" " + Environment.NewLine +
"IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" HandleInput=\"DEC\" " + Environment.NewLine +
"Enum=\"\">" + Environment.NewLine +
"</Param>" + Environment.NewLine + Environment.NewLine +
"<Param Name=\"arraySizeParam\" Type=\"int*\" Len=\"4\" InOut=\"IN\" " + Environment.NewLine +
"Union=\"FALSE\" Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"\" " + Environment.NewLine +
"IsExpGetRef=\"\" IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" " + Environment.NewLine +
"HandleInput=\"HEX\" Enum=\"\">" + Environment.NewLine + Environment.NewLine +
"<Param1 Name=\"arraySizeParam0\" Type=\"int\" Len=\"0\" InOut=\"IN\" " + Environment.NewLine +
"Union=\"FALSE\" Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"1\" " + Environment.NewLine +
"IsExpGetRef=\"\" IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" " + Environment.NewLine +
"HandleInput=\"DEC\" Enum=\"\">" + Environment.NewLine +
"</Param1>" + Environment.NewLine + Environment.NewLine +
"<Param1 Name=\"arraySizeParam1\" Type=\"int\" Len=\"0\" InOut=\"IN\" " + Environment.NewLine +
"Union=\"FALSE\" Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"\" " + Environment.NewLine +
"IsExpGetRef=\"\" IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" " + Environment.NewLine +
"HandleInput=\"HEX\" Enum=\"\">" + Environment.NewLine +
"</Param1>" + Environment.NewLine + Environment.NewLine +
"<Param1 Name=\"arraySizeParam2\" Type=\"int\" Len=\"0\" InOut=\"IN\" " + Environment.NewLine +
"Union=\"FALSE\" Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"\" " + Environment.NewLine +
"IsExpGetRef=\"\" IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" " + Environment.NewLine +
"HandleInput=\"HEX\" Enum=\"\">" + Environment.NewLine +
"</Param1>" + Environment.NewLine + Environment.NewLine +
"<Param1 Name=\"arraySizeParam3\" Type=\"int\" Len=\"0\" InOut=\"IN\" " + Environment.NewLine +
"Union=\"FALSE\" Callback=\"\" CSharpType=\"int\" Value=\"\" ExpectedValue=\"\" " + Environment.NewLine +
"IsExpGetRef=\"\" IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" " + Environment.NewLine +
"HandleInput=\"HEX\" Enum=\"\">" + Environment.NewLine +
"</Param1>" + Environment.NewLine + Environment.NewLine +
"</Param>" + Environment.NewLine +
"<Return Name=\"retVal\" Type=\"int\" Len=\"1\" InOut=\"OUT\" Union=\"FALSE\" " + Environment.NewLine +
"Callback=\"\" CSharpType=\"int\" Value=\"1\" ExpectedValue=\"\" IsExpGetRef=\"\" " + Environment.NewLine +
"IsGetRef=\"\" IsSetRef=\"\" ChildSelected=\"FALSE\" UnionIndex=\"-1\" HandleInput=\"DEC\" " + Environment.NewLine +
"Enum=\"\">" + Environment.NewLine +
"</Return>" + Environment.NewLine +
"</Func>" + Environment.NewLine +
"</FuncXml>" + Environment.NewLine +
"</CustomTypesTable>" + Environment.NewLine +
"</CustomTypesData>" + Environment.NewLine;
StringReader sr = new StringReader(xml);
XmlTextReader xr = new XmlTextReader(sr);
DataTable tbl = new DataTable("CustomTypesTable");
tbl.Columns.Add("Dummy", typeof(uint));
tbl.Columns.Add("FuncXml", typeof(CustomTypeXml));
DataSet ds = new DataSet("CustomTypesData");
ds.Tables.Add(tbl);
ds.ReadXml(xr);
Assert.Equal(1, ds.Tables["CustomTypesTable"].Rows.Count);
xr.Close();
}
示例5: WriteXmlSchema
public void WriteXmlSchema()
{
var ds = new DataSet();
ds.ReadXml(new StringReader(DataProvider.region));
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=\"Root\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">", substring);
Assert.Equal("<xs:schema id=\"Root\" 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);
Assert.Equal(" <xs:element msdata:IsDataSet=\"true\" msdata:Locale=\"en-US\" name=\"Root\">", 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=\"Region\">", 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=\"RegionID\" type=\"xs:string\" minOccurs=\"0\" />", substring);
Assert.Equal(" <xs:element minOccurs=\"0\" name=\"RegionID\" type=\"xs:string\" />", 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=\"RegionDescription\" type=\"xs:string\" minOccurs=\"0\" />", substring);
Assert.Equal(" <xs:element minOccurs=\"0\" name=\"RegionDescription\" type=\"xs:string\" />", 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:choice>", 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);
Assert.Equal("</xs:schema>", TextString);
}
示例6: ReadWriteXml
public void ReadWriteXml()
{
var ds = new DataSet();
ds.ReadXml(new StringReader(DataProvider.region));
TextWriter writer = new StringWriter();
ds.WriteXml(writer);
string TextString = writer.ToString();
string substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal("<Root>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <Region>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <RegionID>1</RegionID>", substring);
// Here the end of line is text markup "\n"
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <RegionDescription>Eastern", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </RegionDescription>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </Region>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <Region>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <RegionID>2</RegionID>", substring);
// Here the end of line is text markup "\n"
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" <RegionDescription>Western", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </RegionDescription>", substring);
substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' }));
TextString = TextString.Substring(TextString.IndexOf('\n') + 1);
Assert.Equal(" </Region>", substring);
Assert.Equal("</Root>", TextString);
}
示例7: WriteXmlEscapeName
public void WriteXmlEscapeName()
{
// create dataset
DataSet data = new DataSet();
DataTable mainTable = data.Tables.Add("main");
DataColumn mainkey = mainTable.Columns.Add("mainkey", typeof(Guid));
mainTable.Columns.Add("col.2<hi/>", typeof(string));
mainTable.Columns.Add("#col3", typeof(string));
// populate data
mainTable.Rows.Add(new object[] { Guid.NewGuid(), "hi there", "my friend" });
mainTable.Rows.Add(new object[] { Guid.NewGuid(), "what is", "your name" });
mainTable.Rows.Add(new object[] { Guid.NewGuid(), "I have", "a bean" });
// write xml
StringWriter writer = new StringWriter();
data.WriteXml(writer, XmlWriteMode.WriteSchema);
string xml = writer.ToString();
Assert.True(xml.IndexOf("name=\"col.2_x003C_hi_x002F__x003E_\"") > 0);
Assert.True(xml.IndexOf("name=\"_x0023_col3\"") > 0);
Assert.True(xml.IndexOf("<col.2_x003C_hi_x002F__x003E_>hi there</col.2_x003C_hi_x002F__x003E_>") > 0);
// read xml
DataSet data2 = new DataSet();
data2.ReadXml(new StringReader(
writer.GetStringBuilder().ToString()));
}
示例8: ReadWriteXml3
public void ReadWriteXml3()
{
string input = @"<FullTextResponse>
<Domains>
<AvailResponse info='y' name='novell-ximian-group' />
<AvailResponse info='n' name='ximian' />
</Domains>
</FullTextResponse>";
var ds = new DataSet();
ds.ReadXml(new StringReader(input));
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xtw.QuoteChar = '\'';
ds.WriteXml(xtw);
xtw.Flush();
Assert.Equal(input.Replace("\r\n", "\n"), sw.ToString().Replace("\r\n", "\n"));
}
示例9: EditingXmlTree
public void EditingXmlTree()
{
XmlDataDocument doc = new XmlDataDocument();
doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
doc.Load(new StringReader(RegionXml));
XmlElement Element = doc.GetElementFromRow(doc.DataSet.Tables[0].Rows[1]);
Element.FirstChild.InnerText = "64";
Assert.Equal("64", doc.DataSet.Tables[0].Rows[1][0]);
DataSet Set = new DataSet();
Set.ReadXml(new StringReader(RegionXml));
doc = new XmlDataDocument(Set);
Element = doc.GetElementFromRow(doc.DataSet.Tables[0].Rows[1]);
Assert.NotNull(Element);
try
{
Element.FirstChild.InnerText = "64";
Assert.False(true);
}
catch (InvalidOperationException)
{
}
Assert.Equal("2", doc.DataSet.Tables[0].Rows[1][0]);
Set.EnforceConstraints = false;
Element.FirstChild.InnerText = "64";
Assert.Equal("64", doc.DataSet.Tables[0].Rows[1][0]);
}
示例10: ISO8859_GB2312
//��������ת��
//��ʵ���ǽ�dataset�����ݶ�����xml�ļ���Ȼ�������
public static DataSet ISO8859_GB2312(DataSet ds)
{
#region
string xml;
xml = ds.GetXml();
ds.Clear();
//�����ַ���
System.Text.Encoding iso8859, gb2312;
//iso8859
iso8859 = System.Text.Encoding.GetEncoding("iso8859-1");
//����2312
gb2312 = System.Text.Encoding.GetEncoding("gb2312");
byte[] bt;
bt = iso8859.GetBytes(xml);
xml = gb2312.GetString(bt);
ds.ReadXml(new System.IO.StringReader(xml));
return ds;
#endregion
}
示例11: ReadXmlSerializable
protected override void ReadXmlSerializable(XmlReader reader)
{
Reset();
var ds = new DataSet();
ds.ReadXml(reader);
if ((ds.Tables["Order Details"] != null))
{
Tables.Add(new Order_DetailsDataTable(ds.Tables["Order Details"]));
}
if ((ds.Tables["Orders"] != null))
{
Tables.Add(new OrdersDataTable(ds.Tables["Orders"]));
}
DataSetName = ds.DataSetName;
Prefix = ds.Prefix;
Namespace = ds.Namespace;
Locale = ds.Locale;
CaseSensitive = ds.CaseSensitive;
EnforceConstraints = ds.EnforceConstraints;
Merge(ds, false, MissingSchemaAction.Add);
InitVars();
}
示例12: GetDataViewByXml
/// <summary>
/// 读取XML返回经排序或筛选后的DataView
/// </summary>
/// <param name="strWhere">筛选条件,如:"name='kgdiwss'"</param>
/// <param name="strSort"> 排序条件,如:"Id desc"</param>
public DataView GetDataViewByXml(string strWhere, string strSort)
{
try
{
string XMLFile = this.XMLPath;
string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() + XMLFile;
DataSet ds = new DataSet();
ds.ReadXml(filename);
DataView dv = new DataView(ds.Tables[0]); //创建DataView来完成排序或筛选操作
if (strSort != null)
{
dv.Sort = strSort; //对DataView中的记录进行排序
}
if (strWhere != null)
{
dv.RowFilter = strWhere; //对DataView中的记录进行筛选,找到我们想要的记录
}
return dv;
}
catch (Exception)
{
return null;
}
}
示例13: GetDataSetByXml
/// <summary>
/// 读取XML返回DataSet
/// </summary>
/// <param name="strXmlPath">XML文件相对路径</param>
public DataSet GetDataSetByXml(string strXmlPath)
{
try
{
DataSet ds = new DataSet();
ds.ReadXml(GetXmlFullPath(strXmlPath));
if (ds.Tables.Count > 0)
{
return ds;
}
return null;
}
catch (Exception)
{
return null;
}
}
示例14: ReadXML
private DataTable ReadXML(string PathToXML)
{
DataSet ds = new DataSet();
ds.ReadXml(PathToXML);
return ds.Tables[0];
}
示例15: IsNull_ByName
public void IsNull_ByName()
{
DataTable dt = new DataTable();
DataColumn dc0 = new DataColumn("Col0", typeof(int));
DataColumn dc1 = new DataColumn("Col1", typeof(int));
dt.Columns.Add(dc0);
dt.Columns.Add(dc1);
dt.Rows.Add(new object[] { 1234 });
DataRow dr = dt.Rows[0];
#region --- assignment ----
// IsNull_S 1
Assert.Equal(false, dr.IsNull("Col0"));
// IsNull_S 2
Assert.Equal(true, dr.IsNull("Col1"));
#endregion
// IsNull_S 1
MemoryStream st = new MemoryStream();
StreamWriter sw = new StreamWriter(st);
sw.Write("<?xml version=\"1.0\" standalone=\"yes\"?><NewDataSet>");
sw.Write("<Table><EmployeeNo>9</EmployeeNo></Table>");
sw.Write("</NewDataSet>");
sw.Flush();
st.Position = 0;
var ds = new DataSet();
ds.ReadXml(st);
// Here we add the expression column
ds.Tables[0].Columns.Add("ValueListValueMember", typeof(object), "EmployeeNo");
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row.IsNull("ValueListValueMember") == true)
Assert.Equal("Failed", "SubTest");
else
Assert.Equal("Passed", "Passed");
}
}