c# 怎么将下面XML里Name的值取出来
<?xmlversion="1.0"encoding="UTF-8"?><TABLE><ROWROWFLAG="1"><COLUMNNAME="ENABLED">1</C...
<?xml version="1.0" encoding="UTF-8"?>
<TABLE>
<ROW ROWFLAG="1">
<COLUMN NAME="ENABLED">1</COLUMN>
<COLUMN NAME="MDM_ID">1203129381</COLUMN>
<COLUMN NAME="OU_ID">10004</COLUMN>
<COLUMN NAME="NAME">北元集团财务管理部</COLUMN>
<COLUMN NAME="SNAME">财务管理部</COLUMN>
<COLUMN NAME="ENAME">Finace Dept.</COLUMN>
<COLUMN NAME="ORDER_ID">04</COLUMN>
<COLUMN NAME="PARENT_ID">100</COLUMN>
<COLUMN NAME="CONTRACT_TEL">0912-8493288</COLUMN>
<COLUMN NAME="LAYER">3</COLUMN>
</ROW>
</TABLE> 展开
<TABLE>
<ROW ROWFLAG="1">
<COLUMN NAME="ENABLED">1</COLUMN>
<COLUMN NAME="MDM_ID">1203129381</COLUMN>
<COLUMN NAME="OU_ID">10004</COLUMN>
<COLUMN NAME="NAME">北元集团财务管理部</COLUMN>
<COLUMN NAME="SNAME">财务管理部</COLUMN>
<COLUMN NAME="ENAME">Finace Dept.</COLUMN>
<COLUMN NAME="ORDER_ID">04</COLUMN>
<COLUMN NAME="PARENT_ID">100</COLUMN>
<COLUMN NAME="CONTRACT_TEL">0912-8493288</COLUMN>
<COLUMN NAME="LAYER">3</COLUMN>
</ROW>
</TABLE> 展开
1个回答
展开全部
public static List<string> GetXmlList(string xmlPath, string tagName,string element1)
{
string strPath = xmlPath;
if (!File.Exists(strPath))
{
return null;
}
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(strPath);
//子节点
XmlElement pElements = XmlDoc.DocumentElement;
XmlNodeList pNodeList = pElements.GetElementsByTagName(tagName);
XmlNode dnode = pNodeList[1];
List<string> key = new List<string>();
// List<string> value = new List<string>();
List<List<string>> list = new List<List<string>>();
foreach (XmlNode pNode in pNodeList)
{
if (pNode.NodeType.ToString() != "Comment")
{
XmlElement pElement = pNode as XmlElement;
key.Add(pElement.GetAttribute(element1).ToString());
// value.Add(pElement.GetAttribute(element2).ToString());
}
}
list.Add(key);
// list.Add(value);
return key;
}
{
string strPath = xmlPath;
if (!File.Exists(strPath))
{
return null;
}
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(strPath);
//子节点
XmlElement pElements = XmlDoc.DocumentElement;
XmlNodeList pNodeList = pElements.GetElementsByTagName(tagName);
XmlNode dnode = pNodeList[1];
List<string> key = new List<string>();
// List<string> value = new List<string>();
List<List<string>> list = new List<List<string>>();
foreach (XmlNode pNode in pNodeList)
{
if (pNode.NodeType.ToString() != "Comment")
{
XmlElement pElement = pNode as XmlElement;
key.Add(pElement.GetAttribute(element1).ToString());
// value.Add(pElement.GetAttribute(element2).ToString());
}
}
list.Add(key);
// list.Add(value);
return key;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询