本文整理汇总了C#中XmlDocument.SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.SelectNodes方法的具体用法?C# XmlDocument.SelectNodes怎么用?C# XmlDocument.SelectNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.SelectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MetaBuild
public static string MetaBuild()
{
var sb = new StringBuilder();
sb.AppendLine("\\\\ hello");
foreach (var proj in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*proj"))
{
sb.AppendLine("\\\\ file: " + proj);
var xml = new XmlDocument();
xml.Load(proj);
var nm = new XmlNamespaceManager(xml.NameTable);
nm.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
foreach (var reference in xml.SelectNodes(@"x:Project\x:ItemGroup\x:Reference"))
{
sb.AppendLine("\\\\" + reference);
}
foreach (var reference in xml.SelectNodes(@"x:Project\x:ItemGroup\x:Reference"))
{
sb.AppendLine("\\\\" + reference);
}
}
return sb.ToString();
}
示例2: Main
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
for (int i = 0; i < files.Length; ++i)
{
doc.Load(files[i]);
List<double> tt = new List<double>();
foreach (XmlElement timing in doc.SelectNodes("//timing"))
{
double val = Convert.ToDouble(timing.GetAttribute("nanosecondsPerLog"), CultureInfo.InvariantCulture);
tt.Add(val);
}
timings.Add(tt);
}
int ordinal = 0;
foreach (XmlElement el in doc.SelectNodes("//timing"))
{
string section = ((XmlElement)el.ParentNode).GetAttribute("logger");
if (ordinal % 4 == 0)
{
Console.WriteLine();
Console.WriteLine("\"{0}\"\t\"NLog\"\t\"Log4Net\"", section);
}
Console.Write("\"{0}\"", el.GetAttribute("name"));
for (int i = 0; i < files.Length; ++i)
{
Console.Write("\t{0}",Math.Round(timings[i][ordinal],3));
}
Console.WriteLine();
ordinal++;
}
}
示例3: btn_login_Click
protected void btn_login_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/XML/User.xml"));
XmlNode root = doc.DocumentElement;
XmlNodeList nodes_name = doc.SelectNodes("/users/user/name");
XmlNodeList nodes_pwd = doc.SelectNodes("/users/user/pwd");
// Kaksoiserittelyn takia mikä tahansa username/password kombinaatio toimii -> korjaukseen
ReadXmlNodesNames(nodes_name);
ReadXmlNodesPwd(nodes_pwd);
if (Session["Username"] != null && Session["Pwd"] != null)
{
lbl_success.Text = "Successfully logged in.";
Session["Login"] = true;
}
else
{
lbl_success.Text = "Failed to login.";
}
/* if (name == txt_name.Text && pwd == txt_pwd.Text)
{
lbl_success.Text = "Successful login.";
}
else
{
lbl_success.Text = name;
// lbl_success.Text = "Login failed.";
}
*/
}
示例4: InitRightMenu
/// <summary>
/// 根据权限初始化菜单
/// </summary>
/// <param name="xmlDoc"></param>
private XmlDocument InitRightMenu(XmlDocument xmlDoc)
{
if (IsVisitor)//--如果是访客则只有总线概况、服务管理两个模块的权限
{
foreach (XmlNode node in xmlDoc.SelectNodes("/Demos/DemoGroup"))
{
if (node.Attributes["Text"].Value != "总线概况" &&
node.Attributes["Text"].Value != "服务管理")
{
node.ParentNode.RemoveChild(node);
}
}
}
else
{
if (!IsSystemAdmin)
{
foreach (XmlNode node in xmlDoc.SelectNodes("/Demos/DemoGroup"))
{
if (node.Attributes["Text"].Value == "系统管理")
{
node.ParentNode.RemoveChild(node);
}
}
}
}
return xmlDoc;
}
示例5: DatasourceforRepeater
public XmlNodeList DatasourceforRepeater(string strHtml)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strHtml);
XmlNodeList xml = xmlDoc.SelectNodes("root");
XmlNodeList xn = xmlDoc.SelectNodes("root/AddContacts");
return xml;
}
示例6: ToJson
/// <summary>
/// XML文档转换成JSON数据
/// </summary>
/// <param name="xmldoc">XML数据文件</param>
/// <returns>返回JSON格式数据记录,以数组方式返回</returns>
public static string ToJson(XmlDocument xmldoc)
{
if (null == xmldoc || null == xmldoc.DocumentElement)
return "";
XmlNode xn = xmldoc.SelectSingleNode("/././.");
if (null == xn)
return "[]";
List<string> tables = new List<string>();
XmlNodeList xnlist = xmldoc.SelectNodes("/./.");
tables.Add(xnlist[0].Name);
foreach (XmlNode xnnode in xnlist)
{
bool isexist = false;
foreach (string t in tables)
{
isexist = xnnode.Name == t;
if (isexist) break;
}
if (isexist) continue;
tables.Add(xnnode.Name);
}
StringBuilder sb = new StringBuilder();
string ft = "\"{0}\":\"{1}\"";
if (tables.Count > 1)
sb.Append("{");
foreach (string t in tables)
{
if (tables.Count > 1)
{
if (t == tables[0])
sb.AppendFormat("\"{0}\":", t);
else
sb.AppendFormat(",\"{0}\":", t);
}
XmlNodeList xnrowlist = xmldoc.SelectNodes("/./" + t);
sb.Append("[");
foreach (XmlNode xnrow in xnrowlist)
{
if (xnrowlist[0] == xnrow)
sb.Append("{");
else
sb.Append(",{");
if (null != xnrow.FirstChild)
sb.AppendFormat(ft, xnrow.FirstChild.Name, xnrow.FirstChild.InnerText.Replace("\"", "\\\""));
for (int i = 1; i < xnrow.ChildNodes.Count; i++)
sb.AppendFormat("," + ft, xnrow.ChildNodes[i].Name, xnrow.ChildNodes[i].InnerText.Replace("\"", "\\\""));
sb.Append("}");
}
sb.Append("]");
}
if (tables.Count > 1)
sb.Append("}");
return sb.ToString();
}
示例7: getCartelCine
public Cartelera getCartelCine()
{
doc = new XmlDocument();
try
{
doc.Load("http://www.cinepolis.com.mx/iphone/xml-iphone.aspx?query=cartelera&ci=" + cartel.CiudadID);
}
catch (Exception e) { return null; }
try
{
complejoInfo = doc.SelectSingleNode("//Cartelera//Complejo[@Complejoid='" + cartel.ComplejoID + "']");
cartel.Complejo = complejoInfo.Attributes.GetNamedItem("Nombre").Value;
cartel.Latitud = complejoInfo.ChildNodes[1].InnerText.Trim();
cartel.Longitud = complejoInfo.ChildNodes[2].InnerText.Trim();
Complejos_peli = doc.SelectNodes("//Cartelera//Complejo[@Complejoid='" + cartel.ComplejoID + "']/Pelicula");
foreach (XmlNode complejo_peli in Complejos_peli)
{
peli = new Pelicula();
string Horario_Peli = "";
peli.PeliculaID = complejo_peli.FirstChild.InnerText;
Complejos_hora = doc.SelectNodes("//Cartelera//Complejo/Pelicula[Peliculaid='" + peli.PeliculaID + "']/Horarios/Horario");
foreach (XmlNode horario in Complejos_hora)
{
Horario_Peli += horario.InnerText + " - ";
}
peliculaInfo = doc.SelectSingleNode("//Peliculas//Pelicula[@Peliculaid='" + peli.PeliculaID + "']");
peli.Nombre = peliculaInfo.Attributes.GetNamedItem("Nombre").Value;
peli.Clasificacion = peliculaInfo.ChildNodes[1].InnerText;
peli.Calificacion = peliculaInfo.ChildNodes[4].InnerText;
peli.Descripcion = peliculaInfo.ChildNodes[6].InnerText;
peli.Director = peliculaInfo.ChildNodes[7].InnerText;
peli.Actor = peliculaInfo.ChildNodes[8].InnerText;
peli.Duracion = peliculaInfo.ChildNodes[16].InnerText;
peli.Trailer = peliculaInfo.ChildNodes[19].InnerText;
peli.Horarios = Horario_Peli;
cartel.Peliculas.Add(peli);
}
}
catch (Exception e) { return null;}
return cartel;
}
示例8: LoadWidget
public override void LoadWidget()
{
StringDictionary settings = GetSettings();
XmlDocument doc = new XmlDocument();
if (settings["content"] != null)
doc.InnerXml = settings["content"];
XmlNodeList links = doc.SelectNodes("//link");
if (links.Count == 0)
{
ulLinks.Visible = false;
}
else
{
foreach (XmlNode node in links)
{
HtmlAnchor a = new HtmlAnchor();
if (node.Attributes["url"] != null)
a.HRef = node.Attributes["url"].InnerText;
if (node.Attributes["title"] != null)
a.InnerText = node.Attributes["title"].InnerText;
if (node.Attributes["newwindow"] != null && node.Attributes["newwindow"].InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
a.Target = "_blank";
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(a);
ulLinks.Controls.Add(li);
}
}
}
示例9: Main
static void Main()
{
//Open xml file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../simple-books.xml");
//Create query to xml file
string xPathQuery = "/catalog/book";
XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);
foreach (XmlNode bookNode in bookList)
{
//Read inforamtion from xml file for each book
string author = bookNode.GetChildText("author");
ArgumentExceptionThrower(author, "author");
string title = bookNode.GetChildText("title");
ArgumentExceptionThrower(title, "title");
string isbnAsString = bookNode.GetChildText("isbn");
long? isbn = (isbnAsString != null) ? long.Parse(isbnAsString) : (long?)null;
string priceAsString = bookNode.GetChildText("price");
decimal? price = (priceAsString != null) ? decimal.Parse(priceAsString) : (decimal?)null;
//Save the book in Bookstore database
BookstoreDAL.AddBook(title, author, isbn, price);
}
}
示例10: Main
static void Main()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../../catalog.xml");
string xPathQuery = "/catalog/album";
XmlNodeList albumsList = xmlDoc.SelectNodes(xPathQuery);
Hashtable hash = new Hashtable();
List<string> autors = new List<string>();
foreach (XmlNode node in albumsList)
{
string autorName = node.SelectSingleNode("artist").InnerText;
if (!hash.ContainsKey(autorName))
{
hash.Add(autorName,1);
autors.Add(autorName);
}
else
{
int count = (int)hash[autorName];
hash[autorName] = count + 1;
}
}
foreach (var autor in autors)
{
Console.WriteLine("Autor: {0} have {1} albums in the catalog.", autor, hash[autor]);
}
}
示例11: Main
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\..\catalogue.xml");
var artists = new Dictionary<string, int>();
string XPath = "/catalogue/album/artist";
XmlNodeList artistsList = doc.SelectNodes(XPath);
foreach (XmlNode node in artistsList)
{
if(!artists.ContainsKey(node.InnerText))
{
artists.Add(node.InnerText, 1);
}else
{
artists[node.InnerText]++;
}
}
foreach (var artist in artists)
{
Console.WriteLine("{0} - {1}", artist.Key, artist.Value);
}
}
示例12: Awake
void Awake ()
{
infoCarrier = GameObject.Find ("InfoCarrier");
if (infoCarrier != null) {
//Set text components
LevelInfo ics = infoCarrier.GetComponent<LevelInfo> ();
LevelText.text = string.Format ("{0}/{1}",
ics.CurrentLevel + 1,
ics.TotalLevels);
XmlDocument xmlDoc = new XmlDocument ();
//Load puzzles.xml
xmlDoc.Load (Path.Combine (Application.persistentDataPath, "Puzzles.xml"));
//Select first group, then pack and last level
XmlNode level = xmlDoc.SelectNodes ("packs/packGroup") [ics.CurrentPack / 10].ChildNodes [ics.CurrentPack % 10].ChildNodes [ics.CurrentLevel];
for (int i = 0; i < level.ChildNodes.Count; i++) {
XmlNode ring = level.ChildNodes [i];
for (int j = 0; j < ring.ChildNodes.Count; j++) {
rings [i].GetChild (j).gameObject.GetComponent<SegmentColor> ().SetColor (int.Parse (ring.ChildNodes [j].InnerXml));
}
}
}
}
示例13: Main
static void Main()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../bookmarks.xml");
string xPathQuery = "/bookmarks/bookmark";
XmlNodeList bookmarksList = xmlDoc.SelectNodes(xPathQuery);
foreach (XmlNode bookmarkNode in bookmarksList)
{
string username = bookmarkNode.GetChildText("username");
string title = bookmarkNode.GetChildText("title");
string url = bookmarkNode.GetChildText("url");
string allTags = bookmarkNode.GetChildText("tags");
string notes = bookmarkNode.GetChildText("notes");
//string[] tags = allTags.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
string[] tags = { };
if (allTags != null)
{
tags = allTags.Split(',');
for (int i = 0; i < tags.Length; i++)
{
tags[i] = tags[i].Trim();
}
}
//Console.WriteLine(username);
AddBookmark(username, title, url, tags, notes);
}
}
示例14: ComplexSearch
static void ComplexSearch(XmlTextWriter writer)
{
BookstoreEntities context = new BookstoreEntities();
using (context)
{
XmlDocument doc = new XmlDocument();
doc.Load(Bookstore.Data.Settings.Default.complexSearchReadFile);
XmlNodeList queries = doc.SelectNodes("/review-queries/query");
foreach (XmlNode query in queries)
{
string type = query.Attributes["type"].Value;
if (type == "by-period")
{
string start = query.SelectSingleNode("start-date").InnerText;
string end = query.SelectSingleNode("end-date").InnerText;
IList<Review> found =
BookstoreDAL.FindReviewPeriod(start, end, context);
WriteResultSet(writer, found);
}
else if (type == "by-author")
{
string author = query.SelectSingleNode("author-name").InnerText;
IList<Review> found =
BookstoreDAL.FindReviewAuthor(author, context);
WriteResultSet(writer, found);
}
SearchLogsImporter.AddLog(DateTime.Now, query.OuterXml);
}
}
}
示例15: Main
/* 11. Write a program, which extract from the file catalog.xml the prices for all albums,
* published 5 years ago or earlier. Use XPath query.*/
static void Main(string[] args)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("../../catalog.xml");
string xPathQuery = "/catalog/album";
XmlNodeList albums = xmlDoc.SelectNodes(xPathQuery);
var prices = new List<decimal>();
foreach (XmlNode album in albums)
{
var year = int.Parse(album.SelectSingleNode("year").InnerText);
var publishDate = new DateTime(year, 1, 1);
if (DateTime.Now.Year - publishDate.Year > 5)
{
prices.Add(decimal.Parse(album.SelectSingleNode("price").InnerText));
}
}
foreach (var price in prices)
{
Console.WriteLine(price);
}
}