xml返回数组数据

xml中数据形式如下:

  <!--公司部门-->  

<SystemgConfig>

<Dept>    

<DeptItem name="ComDept">第一制造部</DeptItem>

<DeptItem name="ComDept">第二制造部</DeptItem>

 <DeptItem name="ComDept">第三制造部</DeptItem>

</Dept>

</SystemgConfig>

要取得返回数组

public XmlNodeList GetXMLdataList(string xmlFilePath, string nodeName) {

XmlDocument objXD = new XmlDocument();

objXD.Load(xmlFilePath);

XmlNamespaceManager objXNM = new XmlNamespaceManager(objXD.NameTable); //读取节点值 

XmlNodeList xmlList = objXD.SelectNodes(nodeName, objXNM); //node.InnerText 就是读取出来的值

return xmlList;

}

调用并处理

其中nodeName参数应写成"/SystemgConfig/Dept/DeptItem "

XmlNodeList xnl = GetXMLdataList(string xmlFilePath, string nodeName)

for(int i=0;i<xnl.count;i++){

string value = xnl.item(i).innerText;s

}

一切尽在淘婚网www.taohunla.com
原文地址:https://www.cnblogs.com/litao9026/p/2264419.html