日期:2014-05-20  浏览次数:20718 次

关于操作xml
ppConfig.xml

<?xml   version= "1.0 "   encoding= "gb2312 "?>
<AppConfig>
<Area>
<Language>ZH</Language>
<List>
<Item>中文[ZH]</Item>
<Item>英文[EN]</Item>
</List>
</Area>
<Area>
<Language>EN</Language>
<List>
<Item>Chinese[ZH]</Item>
<Item>English[EN]</Item>
</List>
</Area>
<Area>
</AppConfig>  


IList   result   =   new   ArrayList();

XmlReader   reader   =   new   XmlTextReader( "resources/AppConfig.xml ");
XmlDocument   doc   =   new   XmlDocument();
doc.Load(reader);

XmlNode   root   =   doc.DocumentElement;
XmlNodeList   nodelist   =   root.SelectNodes( "Area[Language= ' "   +   lang   +   "/List/Item ");//请问SelectNodes()这个涵数里的参数是什么意思。


------解决方案--------------------
TO:
( "Area[Language= ' " + lang + "/List/Item ");
我写这个我试了一下告诉不对,正确形式怎么写啊。

try..

string lang= "ZH ";
XmlNodeList nodelist = root.SelectNodes( "Area[Language= ' " + lang + " ']/List/Item ");


------解决方案--------------------
for example:

XmlDocument doc = new XmlDocument();
doc.Load(@ "../../test.xml ");
XmlNode root = doc.DocumentElement;
string lang= "ZH ";
XmlNodeList nodes = root.SelectNodes( "Area[Language= ' " + lang + " ']/List/Item ");
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.InnerText);
}

输出:
中文[ZH]
英文[EN]