将xml多个相同下节点的分类获取 C#
<InformationVersion="1.0.1"><SoftWare><Browsers><DefaultBrowser>...</DefaultBrowser><...
<Information Version="1.0.1">
<SoftWare>
<Browsers>
<DefaultBrowser>...</DefaultBrowser>
<Browser>
<Name>Mozilla Firefox</Name>
<Version>25.0.1</Version>
<HomePage>about:cehome</HomePage>
<SearchEngines>
<DefaultSearchEngine>
<Name>�ٶ�</Name>
</DefaultSearchEngine>
<SearchEngine>
<Name>卓越亚马逊</Name>
</SearchEngine>
<SearchEngine>
<Name>百度</Name>
</SearchEngine>
<SearchEngine>
<Name>Google</Name>
</SearchEngine>
<SearchEngine>
<Name>淘宝购物</Name>
</SearchEngine>
<SearchEngine>
<Name>当当网</Name>
</SearchEngine>
<SearchEngine>
<Name>有道</Name>
</SearchEngine>
<SearchEngine>
<Name>百度知道</Name>
</SearchEngine>
<SearchEngine>
<Name>Bing</Name>
</SearchEngine>
<SearchEngine>
<Name>Creative Commons</Name>
</SearchEngine>
<SearchEngine>
<Name>易趣网</Name>
</SearchEngine>
<SearchEngine>
<Name>拍拍网</Name>
</SearchEngine>
<SearchEngine>
<Name>维基百科</Name>
</SearchEngine>
</SearchEngines>
<Plugins>...</Plugins>
</Browser>
<Browser>
<Name>Google Chrome</Name>
<Version>38.0.2125.104</Version>
<HomePage/>
<SearchEngines>
<DefaultSearchEngine>
<Name>Google</Name>
</DefaultSearchEngine>
<SearchEngine>
<Name>百度</Name>
</SearchEngine>
<SearchEngine>
<Name>搜狗</Name>
</SearchEngine>
<SearchEngine>
<Name>Bing</Name>
</SearchEngine>
</SearchEngines>
<Plugins/>
</Browser>
</Browsers>
</SoftWare>
</Information>
补充:如何获取SoftWare/Browsers/Browser下的HomePage和SearchEngines,并把Firefox的HomePage放在richtextbox1中,Google的HomePage放在richtextbox2中,Firefox同节点里的SearchEngine添加到combobox1,Google添加到combobox2中去。 展开
<SoftWare>
<Browsers>
<DefaultBrowser>...</DefaultBrowser>
<Browser>
<Name>Mozilla Firefox</Name>
<Version>25.0.1</Version>
<HomePage>about:cehome</HomePage>
<SearchEngines>
<DefaultSearchEngine>
<Name>�ٶ�</Name>
</DefaultSearchEngine>
<SearchEngine>
<Name>卓越亚马逊</Name>
</SearchEngine>
<SearchEngine>
<Name>百度</Name>
</SearchEngine>
<SearchEngine>
<Name>Google</Name>
</SearchEngine>
<SearchEngine>
<Name>淘宝购物</Name>
</SearchEngine>
<SearchEngine>
<Name>当当网</Name>
</SearchEngine>
<SearchEngine>
<Name>有道</Name>
</SearchEngine>
<SearchEngine>
<Name>百度知道</Name>
</SearchEngine>
<SearchEngine>
<Name>Bing</Name>
</SearchEngine>
<SearchEngine>
<Name>Creative Commons</Name>
</SearchEngine>
<SearchEngine>
<Name>易趣网</Name>
</SearchEngine>
<SearchEngine>
<Name>拍拍网</Name>
</SearchEngine>
<SearchEngine>
<Name>维基百科</Name>
</SearchEngine>
</SearchEngines>
<Plugins>...</Plugins>
</Browser>
<Browser>
<Name>Google Chrome</Name>
<Version>38.0.2125.104</Version>
<HomePage/>
<SearchEngines>
<DefaultSearchEngine>
<Name>Google</Name>
</DefaultSearchEngine>
<SearchEngine>
<Name>百度</Name>
</SearchEngine>
<SearchEngine>
<Name>搜狗</Name>
</SearchEngine>
<SearchEngine>
<Name>Bing</Name>
</SearchEngine>
</SearchEngines>
<Plugins/>
</Browser>
</Browsers>
</SoftWare>
</Information>
补充:如何获取SoftWare/Browsers/Browser下的HomePage和SearchEngines,并把Firefox的HomePage放在richtextbox1中,Google的HomePage放在richtextbox2中,Firefox同节点里的SearchEngine添加到combobox1,Google添加到combobox2中去。 展开
展开全部
//数据都帮你取出来完了,摆控件赋值自个弄弄就好了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace XMLTest
{
class Program
{
static void Main(string[] args)
{
XmlDocument xml = new XmlDocument();
xml.Load("aa.xml");
XmlNode xe = xml.SelectSingleNode("Information/SoftWare/Browsers");
foreach (XmlNode item in xe.ChildNodes)
{
if (item.Name == "Browser")
{
if (item.SelectSingleNode("Name").InnerText == "Mozilla Firefox")
{
Console.WriteLine(item.SelectSingleNode("Name").InnerText);
Console.WriteLine(item.SelectSingleNode("Version").InnerText);
Console.WriteLine(item.SelectSingleNode("HomePage").InnerText);
XmlNode searchEnginesNode = item.SelectSingleNode("SearchEngines");
foreach (XmlNode itemEngine in searchEnginesNode.ChildNodes)
{
Console.WriteLine(itemEngine.SelectSingleNode("Name").InnerText);
}
}
else if (item.SelectSingleNode("Name").InnerText == "Google Chrome")
{
Console.WriteLine(item.SelectSingleNode("Name").InnerText);
Console.WriteLine(item.SelectSingleNode("Version").InnerText);
Console.WriteLine(item.SelectSingleNode("HomePage").InnerText);
XmlNode searchEnginesNode = item.SelectSingleNode("SearchEngines");
foreach (XmlNode itemEngine in searchEnginesNode.ChildNodes)
{
Console.WriteLine(itemEngine.SelectSingleNode("Name").InnerText);
}
}
}
}
Console.ReadKey();
}
}
}
追问
嗯,已经做出来,还是谢谢你!
追答
...........................................
展开全部
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/Config/BusinessCategory.xml"));
XmlElement rootElem = xmlDoc.DocumentElement; //获取根节点
XmlNodeList BusinessCategoryNodes = rootElem.GetElementsByTagName("BusinessCategory");
string html = "";
List<BusinessTypeOptions> _lBusinessTypeOptions = new List<BusinessTypeOptions>();
_lBusinessTypeOptions = obj_BusinessTypeOptions.GetByCategoryID(CategoryID);
foreach (XmlNode node in BusinessCategoryNodes)
{
}
读取XML
xmlDoc.Load(Server.MapPath("~/Config/BusinessCategory.xml"));
XmlElement rootElem = xmlDoc.DocumentElement; //获取根节点
XmlNodeList BusinessCategoryNodes = rootElem.GetElementsByTagName("BusinessCategory");
string html = "";
List<BusinessTypeOptions> _lBusinessTypeOptions = new List<BusinessTypeOptions>();
_lBusinessTypeOptions = obj_BusinessTypeOptions.GetByCategoryID(CategoryID);
foreach (XmlNode node in BusinessCategoryNodes)
{
}
读取XML
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询