0
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);
4

1 回答 1

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"]);
}
于 2012-10-10T13:03:39.647 回答