我有 XML 之类的
<rss>
<channel>
<item>
<category domain="category" nicename="change"><![CDATA[Changing Lives]]></category>
<category domain="category" nicename="events"><![CDATA[Events]]></category>
<category domain="category" nicename="leadership"><![CDATA[Leadership]]></category>
<category domain="category" nicename="spiritual-transformation"><![CDATA[Spiritual Transformation]]></category>
</item>
<item></item>
<item></item>
</channel>
</rss>
我正在尝试阅读类别内部文本(改变生活,事件,领导力)......使用 foreach 条件......但是对于每个循环,我只得到改变生活......这是我的代码
protected void btnImportPost_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
string strPath = Server.MapPath("~/App_Data/willowcreekassociationblog.wordpress.xml");
doc.Load(strPath);
//Get Channel Node
XmlNode channelNode = doc.SelectSingleNode("rss/channel");
if (channelNode != null)
{
DateTime temp;
//Add NameSpace
XmlNamespaceManager nameSpace = new XmlNamespaceManager(doc.NameTable);
nameSpace.AddNamespace("excerpt", "http://wordpress.org/export/1.2/excerpt/");
nameSpace.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/");
nameSpace.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
nameSpace.AddNamespace("wfw", "http://wellformedweb.org/CommentAPI/");
nameSpace.AddNamespace("wp", "http://wordpress.org/export/1.2/");
//Parse each item
foreach (XmlNode itemNode in channelNode.SelectNodes("item"))
{
//some code here
foreach (XmlNode categoryNode in itemNode.SelectNodes("category"))
{
//CMS.SiteProvider.CategoryInfo GetCate = null;
string CategoryName = itemNode.SelectSingleNode("category").InnerText;
Response.Write(@"<script language='javascript'>alert('root Document:" + CategoryName + "');</script>");
}
}
}
}