简单的Xml文件如下
<?xml version="1.0" encoding="gbk"?>
<root>
<introduce>总体语音系统规划文档</introduce>
<currentPart>在线</currentPart>
</root>
现在知道Xml中有<currentPart>这个标签,就指定这个标签,然后取出内容
怎么完成?
高手指教!
谢谢
<?xml version="1.0" encoding="gbk"?>
<root>
<introduce>总体语音系统规划文档</introduce>
<currentPart>在线</currentPart>
</root>
现在知道Xml中有<currentPart>这个标签,就指定这个标签,然后取出内容
怎么完成?
高手指教!
谢谢
doc.GetElementById("currentPart")
/// 获取指定节点的值
/// </summary>
/// <param name="strXmlFile">XML文件</param>
/// <param name="strSelectNodes">节点的Xpath</param>
/// <param name="strSelectSingleNode">要获取的改节点名称</param>
/// <returns>ArrayList</returns>
public ArrayList GetSpecifyNodeValue(String strXmlFile, String strSelectNodes, String strSelectSingleNode)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXmlFile);
ArrayList al = new ArrayList();
XmlNodeList xmlNL = xmlDoc.SelectNodes(strSelectNodes);
foreach (System.Xml.XmlNode xmlN in xmlNL)
{
XmlElement xe = (XmlElement)xmlN.SelectSingleNode(strSelectSingleNode);
al.Add(xe.InnerText);
}
return al;
}
/// <summary>
/// 获取指定节点的属性
/// </summary>
/// <param name="strXmlFile">XML文件</param>
/// <param name="strSelectNodes">节点的Xpath</param>
/// <param name="strSelectSingleNode">要获取的改节点名称</param>
/// <param name="strAttribute">要获取的改节点的属性名称</param>
/// <returns>ArrayList</returns>
public ArrayList GetSpecifyNodeAttribute(String strXmlFile, String strSelectNodes, String strSelectSingleNode, String strAttribute)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXmlFile);
ArrayList al = new ArrayList();
XmlNodeList xmlNL = xmlDoc.SelectNodes(strSelectNodes);
foreach (System.Xml.XmlNode xmlN in xmlNL)
{
XmlElement xe = (XmlElement)xmlN.SelectSingleNode(strSelectSingleNode);
al.Add(xe.GetAttribute(strAttribute));
}
return al;
}
DataSet dsCount = new DataSet();
dsCount.ReadXml(path);
string value=dsCount.Tables[0].rows[0]["currentPart"].ToString();
//注value就是你要的值