如何从xmlnodelist node = doc.getelementsbytagname中查找内部文本

时间:2012-10-10 12:42:19

标签: c#

XmlNodeList node = DOC.GetElementsByTagName("CheckMarkObject");

        foreach (XmlNode nodes in node)
        {
            string name = null;
             name = node.innertext;
        }



        checkmark.Label = node[0].InnerText;   
        checkmark.Name = node[0].InnerText;
        //checkmark.IsChecked = form[0].InnerText;
        CreateControlsUsingObjects(checkmark);

1 个答案:

答案 0 :(得分:1)

变量名称应该是其他方式

   XmlNodeList nodes = DOC.GetElementsByTagName("CheckMarkObject");

    foreach (XmlNode node in nodes)
    {
        string name = node.InnerText;
    }

更新

   //using System.Data;
   public DataTable getNodesData(XmlNodeList nodes)
    {
        DataTable dt = new DataTable();

        if (nodes.Count <= 0)
            return dt;

        foreach (XmlNode childnode in nodes[0].ChildNodes)
            dt.Columns.Add(childnode.Name);

        foreach (XmlNode node in nodes)
        {
            DataRow dr = dt.NewRow();
            foreach (XmlNode childnode in node.ChildNodes)
                dr[childnode.Name] = childnode.InnerText;

            dt.Rows.Add(dr);
        }

        return dt;
    }

    XmlNodeList nodes = DOC.GetElementsByTagName("CheckMarkObject");
    DataTable dt = getNodesData(nodes); 

    //Bind your dt to GridView, DataList, Repeater etc

foreach(DataRow row in dt.Rows)
{
    print(row["Name"]);
    print(row["IsChecked"]);
    print(row["Label"]);
}