本文整理汇总了C#中System.Xml.XmlDataDocument类的典型用法代码示例。如果您正苦于以下问题:C# XmlDataDocument类的具体用法?C# XmlDataDocument怎么用?C# XmlDataDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlDataDocument类属于System.Xml命名空间,在下文中一共展示了XmlDataDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//try
//{
if (this.RssUrl.Length == 0)
throw new ApplicationException("Не указана ссылка на RSS-ленту.");
XmlDataDocument feed = new XmlDataDocument();
feed.Load(GetFullUrl(this.RssUrl));
XmlNodeList posts = feed.GetElementsByTagName("item");
DataTable table = new DataTable("Feed");
table.Columns.Add("Title", typeof(string));
table.Columns.Add("Description", typeof(string));
table.Columns.Add("Link", typeof(string));
table.Columns.Add("PubDate", typeof(DateTime));
foreach (XmlNode post in posts)
{
DataRow row = table.NewRow();
row["Title"] = post["title"].InnerText;
row["Description"] = post["description"].InnerText.Trim();
row["Link"] = post["link"].InnerText;
row["PubDate"] = DateTime.Parse(post["pubDate"].InnerText);
table.Rows.Add(row);
}
dlArticles.DataSource = table;
dlArticles.DataBind();
//}
/*catch (Exception)
{
this.Visible = false;
}*/
}
示例2: loaddata
public void loaddata()
{
XmlDataDocument xml = new XmlDataDocument();
xml.Load(Server.MapPath("~/" + "ad.xml"));
XmlNodeList nodes = xml.SelectSingleNode("ttt").ChildNodes;
DataTable dt = new DataTable();
dt.Columns.Add("index", typeof(string));
dt.Columns.Add("src", typeof(string));
dt.Columns.Add("href", typeof(string));
dt.Columns.Add("target", typeof(string));
foreach (XmlNode node in nodes)
{
DataRow row = dt.NewRow();
row["href"] = node.Attributes["href"].Value;
row["src"] = node.Attributes["src"].Value;
dt.Rows.Add(row);
}
DataList4.DataSource = dt;
DataList4.DataBind();
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string connStr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI;";
using (SqlConnection conn = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand("select * from customers", conn);
conn.Open();
DataSet ds = new DataSet();
ds.DataSetName = "Customers";
ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "Customer");
//Response.ContentType = "text/xml";
//ds.WriteXml(Response.OutputStream);
//Added in Listing 13-15
XmlDataDocument doc = new XmlDataDocument(ds);
doc.DataSet.EnforceConstraints = false;
XmlNode node = doc.SelectSingleNode(@"//Customer[CustomerID = 'ANATR']/ContactTitle");
node.InnerText = "Boss";
doc.DataSet.EnforceConstraints = true;
DataRow dr = doc.GetRowFromElement((XmlElement)node.ParentNode);
Response.Write(dr["ContactName"].ToString() + " is the ");
Response.Write(dr["ContactTitle"].ToString());
}
}
示例4: AddLink
public void AddLink(string title, string uri)
{
XmlDocument doc = new XmlDataDocument();
doc.Load("RssLinks.xml");
XmlNode rootNode = doc.SelectSingleNode("links");
XmlNode linkNode = doc.CreateElement("link");
XmlNode titleNode = doc.CreateElement("title");
XmlText titleText = doc.CreateTextNode(title);
titleNode.AppendChild(titleText);
XmlNode uriNode = doc.CreateElement("uri");
XmlText uriText = doc.CreateTextNode(uri);
uriNode.AppendChild(uriText);
XmlNode defaultshowNode = doc.CreateElement("defaultshow");
XmlText defaultshowText = doc.CreateTextNode("false");
defaultshowNode.AppendChild(defaultshowText);
linkNode.AppendChild(titleNode);
linkNode.AppendChild(uriNode);
linkNode.AppendChild(defaultshowNode);
rootNode.AppendChild(linkNode);
doc.Save("RssLinks.xml");
}
示例5: XmlFile
public XmlFile(string FileName)
{
this.strDataFileName = FileName;
this.mydoc = new XmlDataDocument();
this.mydoc.Load(this.strDataFileName);
this.mydoc.DataSet.EnforceConstraints = false;
}
示例6: getLatLong
public IDictionary<String, String> getLatLong(String zipCode)
{
XmlDataDocument doc = new XmlDataDocument();
List<String> data = new List<String>();
String url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + zipCode;
doc.Load(url);
XmlNodeList status = doc.GetElementsByTagName("status");
String res_status = status[0].InnerText;
if (!res_status.Equals("OK"))
{
data.Add("No Result");
}
XmlNodeList result = doc.GetElementsByTagName("result");
XmlNodeList list = null,location = null;
String latitude = null, longitude = null;
for (int i = 0; i < result.Count; i++)
{
list = doc.GetElementsByTagName("geometry");
}
for (int i = 0; i < list.Count; i++)
{
location = doc.GetElementsByTagName("location");
}
latitude = location[0].SelectSingleNode("lat").InnerText;
longitude = location[0].SelectSingleNode("lng").InnerText;
return getWeatherData(latitude,longitude);
}
示例7: getWeatherData
public IDictionary<String, String> getWeatherData(String lat, String lon)
{
XmlDataDocument doc = new XmlDataDocument();
IDictionary<String, String> data = new Dictionary<String, String>();
String url ="http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + lat + "&lon=" + lon + "&cnt=5&mode=xml";
doc.Load(url);
XmlNodeList locationList = doc.GetElementsByTagName("location");
XmlNodeList foreCastList = doc.GetElementsByTagName("time");
data["City"] = locationList[0].SelectSingleNode("name").InnerText;
data["Country"] = locationList[0].SelectSingleNode("country").InnerText;
String temperature,wind,clouds;
for (int i = 0; i < 5; i++)
{
temperature = "Temperature : Morn = " + foreCastList[i].SelectSingleNode("temperature").Attributes["morn"].Value +
",Evening = " + foreCastList[i].SelectSingleNode("temperature").Attributes["eve"].Value + ",Night = " + foreCastList[i].SelectSingleNode("temperature").Attributes["night"].Value;
wind = "Wind : " + foreCastList[i].SelectSingleNode("windSpeed").Attributes["name"].Value;
clouds = "Clouds : " + foreCastList[i].SelectSingleNode("clouds").Attributes["value"].Value;
data[foreCastList[i].Attributes["day"].Value] = temperature + " | " + wind + " | " + clouds;
}
return data;
}
示例8: readChannelFeed
public void readChannelFeed()
{
XmlDataDocument xmldoc = new XmlDataDocument();
XmlNodeList xmlnode;
int i = 0;
//string str = null;
xmldoc.Load(formHTTPrequest());
xmlnode = xmldoc.GetElementsByTagName("feed");
feedCount = xmlnode.Count;
dates = new string[xmlnode.Count];
ids = new string[xmlnode.Count];
temp = new string[xmlnode.Count];
air = new string[xmlnode.Count];
soil = new string[xmlnode.Count];
light = new string[xmlnode.Count];
co2_1 = new string[xmlnode.Count];
co2_2 = new string[xmlnode.Count];
out_temp = new string[xmlnode.Count];
for (i = 0; i <= xmlnode.Count - 1; i++)
{
dates[i] = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
ids[i] = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
temp[i] = xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
air[i] = xmlnode[i].ChildNodes.Item(3).InnerText.Trim();
soil[i] = xmlnode[i].ChildNodes.Item(4).InnerText.Trim();
light[i] = xmlnode[i].ChildNodes.Item(5).InnerText.Trim();
co2_1[i] = xmlnode[i].ChildNodes.Item(6).InnerText.Trim();
co2_2[i] = xmlnode[i].ChildNodes.Item(7).InnerText.Trim();
out_temp[i] = xmlnode[i].ChildNodes.Item(8).InnerText.Trim();
}
}
示例9: button1_Click
private void button1_Click(object sender, System.EventArgs e)
{
XmlDataDocument doc = new XmlDataDocument ();
doc.Load ( "locdata.xml" );
XmlNodeList nodes = doc.GetElementsByTagName("city");
foreach ( XmlNode n in nodes )
{
listBox1.Items.Add ( n.InnerText );
}
label1.Text = string.Format("Total {0} Item(s).", listBox1.Items.Count);
// StreamReader reader = new StreamReader ( "loctest2.csv" );
// string contents = reader.ReadToEnd ();
// reader.Close ();
// foreach ( string s in contents.Split ( "\n\r".ToCharArray() ) )
// {
// if ( s.Trim() == string.Empty ) continue;
// foreach ( string p in s.Split ( ",".ToCharArray() ) )
// {
// string temp = p.Replace ( "\"", "" );
// listBox1.Items.Add ( temp.Trim() );
// }
//
//
// }
}
示例10: AddLineLayerRule
public bool AddLineLayerRule(Page oPage, string sFilter, string width, string linestyle, string color)
{
try
{
if (this.LayerDefXmlString != "")
{
this.LayerDefXml = new XmlDataDocument();
this.LayerDefXml.LoadXml(this.LayerDefXmlString);
}
else if (this.LayerDefXml == null)
{
return false;
}
XmlNode pRule = this.LayerDefXml.GetElementsByTagName("LineRule")[0].Clone();
pRule.SelectSingleNode("Filter").InnerText = sFilter;
pRule.SelectSingleNode("LineSymbolization2D/LineStyle").InnerText = linestyle;
pRule.SelectSingleNode("LineSymbolization2D/Thickness").InnerText = width;
pRule.SelectSingleNode("LineSymbolization2D/Color").InnerText = color.ToUpper();
this.LayerDefXml.GetElementsByTagName("LineTypeStyle")[0].AppendChild(pRule);
this.LayerDefXmlString = this.LayerDefXml.OuterXml;
this.layerDefContent = new MgByteSource(Encoding.UTF8.GetBytes(this.LayerDefXml.OuterXml), this.LayerDefXml.OuterXml.Length).GetReader();
return true;
}
catch
{
return false;
}
}
示例11: getObjectList
/// <summary>
/// Возвращает массив объектов по структуре SysObject
/// </summary>
/// <returns></returns>
public ArrayList getObjectList()
{
ArrayList arrField = new ArrayList();
SysObject sObject;
DataSet DS = new DataSet();
try
{
GetXMLFileData(DS, Config_Protocol);
}
catch (Exception e)
{
string sError = e.Message;
}
DataRow row;
XmlDataDocument XDoc = new XmlDataDocument(DS);
XmlNodeList ProtocolNode = XDoc.DocumentElement.SelectNodes("//objects/obj");
foreach (XmlNode xmlNode in ProtocolNode)
{
row = XDoc.GetRowFromElement((XmlElement)xmlNode);
if (row != null)
{
sObject.Index= Convert.ToInt16(row[0].ToString());
sObject.Type = row[1].ToString();
arrField.Add(sObject);
}
}
return arrField;
}
示例12: 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);
}
示例13: RetrieveFilterData
public static DataTable RetrieveFilterData(string filterPath)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Category", typeof(string)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Value", typeof(string)));
DataSet ds = new DataSet();
ds.ReadXml(filterPath);
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
string strXPathQuery = "/root/filter";
string category = string.Empty;
string itemName = string.Empty;
string itemValue = string.Empty;
DataRow dr = null;
foreach (XmlNode nodeDetail in xmlDataDoc.SelectNodes(strXPathQuery))
{
category = nodeDetail.ChildNodes[0].InnerText.ToString();
itemName = nodeDetail.ChildNodes[1].InnerText.ToString();
itemValue = nodeDetail.ChildNodes[2].InnerText.ToString();
dr = dt.NewRow();
dr["Category"] = category;
dr["Name"] = itemName;
dr["Value"] = itemValue;
dt.Rows.Add(dr);
}
return dt;
}
示例14: createCsvFile
private void createCsvFile()
{
XmlDataDocument xmldoc = new XmlDataDocument();
string name = null;
string year = null;
string corp = null;
string line = null;
string code = null;
XmlNodeList childs = null;
StreamWriter file = new StreamWriter(mamePath + "roms.csv", false);
FileStream fs = new FileStream(mamePath + "mame.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
XmlNodeList machineNodes = xmldoc.GetElementsByTagName("machine");
for (int i = 0; i < machineNodes.Count; i++)
{
code = machineNodes[i].Attributes.GetNamedItem("name").InnerText.Trim();
childs = machineNodes[i].ChildNodes;
name = childs.Count > 0 ? childs.Item(0).InnerText.Trim() : "";
year = childs.Count > 1 ? childs.Item(1).InnerText.Trim() : "";
corp = childs.Count > 2 ? childs.Item(2).InnerText.Trim() : "";
line = segment(code) + ", " + segment(name) + ", " + segment(year) + ", " + segment(corp);
file.WriteLine(line);
//if (i > 10) {
// break;
//}
}
file.Close();
fs.Close();
}
示例15: Form1_Load
private void Form1_Load(object sender, System.EventArgs e)
{
this.dataSet1.ReadXmlSchema ( "locdataschema.xsd" );
XmlDataDocument datadoc = new XmlDataDocument ( dataSet1 );
datadoc.Load ( "locdata.xml" );
this.dataGrid1.DataSource = this.dataSet1.Tables["loctest"];
}