XML如下:
  
<Entity>
    <Code>11110</Code>
    <Des>镇域范围</Des>
    <EntType>LWPOLYLINE,POLYLINE</EntType>
    <LayerName>04镇域范围</LayerName>
    <ColorIndex />
    <IsClose />
    <LineType>Center</LineType>
    <LineWidth />
    <GlobeWidth />
    <HasHatch />
    <Thickness />
    <Attribute ID="111100">getattr01x</Attribute>
    <Ent tag="3" />
  </Entity>C#点击加载的代码: DataSet set = new DataSet();
            //用set读取xml文件
            set.ReadXml(@"E:\\Entitys.xml");
            //设置dataGridView的数据源
            //DataGridView1.DataSource = set.Tables[0];
           this.DataGridView1.AutoGenerateColumns = true;
           this.DataGridView1.DataSource = set.Tables[0].DefaultView;
    <Attribute ID="111100">getattr01x</Attribute>
    <Ent tag="3" />
没有显示  应该怎么做

解决方案 »

  1.   


    由于每个实体都不一样
    这是第二个   <Entity>
        <Code>11120</Code>
        <Des>镇区范围</Des>
        <EntType>LWPOLYLINE,POLYLINE</EntType>
        <LayerName>05镇区范围</LayerName>
        <ColorIndex />
        <IsClose />
        <LineType>Center</LineType>
        <LineWidth />
        <GlobeWidth />
        <HasHatch />
        <Thickness />
        <Attribute ID="111200">getattr01x</Attribute>
        <Ent tag="3" />
      </Entity>
      

  2.   

    参考一下!
    datagridview 操作多级节点的xml文件问题
      

  3.   

    http://hiphotos.baidu.com/lanche/pic/item/74e01ef36f4c00890b46e0d3.jpg
      

  4.   

    是不是这里的<Attribute ID="111100">getattr01x</Attribute>
        <Ent tag="3" />
    应该改成
    <Attribute ID="111100">getattr01x</Attribute>
        <Ent>3</Ent>
      

  5.   

    re:8
    我当时也想过 
    但是按标准这个XML是不让改的
    如果不改的话 怎么做?
      

  6.   

    每个实体中  这两个都是不一样的 我想加载显示 这两项 不行
        <Attribute ID="111200">getattr01x</Attribute>
        <Ent tag="3" />
      

  7.   

    先把xml读取到dataset啊,再绑定到datagridview。
      

  8.   


    DataSet set = new DataSet();
                //用set读取xml文件
                set.ReadXml(@"E:\\Entitys.xml");
                //设置dataGridView的数据源
                //DataGridView1.DataSource = set.Tables[0];
               this.DataGridView1.AutoGenerateColumns = true;
               this.DataGridView1.DataSource = set.Tables[0].DefaultView;
    我已经绑定了  是最后那两个节点显示的问题  
      

  9.   

    DataGridView是二维的表,你的数据是表中有嵌套的数据,你要怎么显示他?
      

  10.   

    如果你的节点是固定这种格式的话,,你其实可以自己写一个方法的
    专门去读取这个节点用 xPath 去定位这个节点找到值  然后在刚才加载的 DataSet里增加一个行至于更简单的方法,,目前没想到,对XML只是刚做了一些  没太深入
      

  11.   

    XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load("a.xml");
    XmlNode node = xmldoc.SelectSingleNode("");
    if (node == null)
    {}
    foreach (XmlNode xnode in xmldoc.SelectNodes(""))
    {   
     DataRow row = dt.NewRow();
    foreach (XmlNode xcnode in xnode.ChildNodes)
    {
     row[xcnode.Name] = xcnode.InnerText;
    }
     dt.Rows.Add(row);
    }
    }
      

  12.   


    不太对我这样写  但是还是不行 求高手
                //XmlNodeList nodes = Doc.SelectNodes("//Entitys/Entitys");
                foreach (XmlNode node in nodes)
                {
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        XmlNode cellnode = node.ChildNodes[i];
                        string cellname = "Cell" + i.ToString();
                        if (!dataGridView1.Columns.Contains(cellname))
                        {
                            DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                            column.HeaderText = cellnode.Attributes["name"].Value;
                            column.Name = cellname;
                            dataGridView1.Columns.Add(column);
                        }
                        if (i == 0)
                            dataGridView1.Rows.Add(1);
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[cellname].Value = cellnode.InnerText;
                    }
                }
            }
      

  13.   

       this.DataGridView1.AutoGenerateColumns = true;
               this.DataGridView1.DataSource = set.Tables[0].DefaultView;
               GridView1.DataBind();
      

  14.   


    能显示 
    只是嵌套的那两个不行
    <Entity>
    <Code>11110</Code>
    <Des>镇域范围</Des>
    <EntType>LWPOLYLINE,POLYLINE</EntType>
    <LayerName>04镇域范围</LayerName>
    <ColorIndex></ColorIndex>
    <IsClose></IsClose>
    <LineType>Center</LineType>
    <LineWidth></LineWidth>
    <GlobeWidth></GlobeWidth>
    <HasHatch></HasHatch>
    <Thickness></Thickness>
    <Attribute ID="111100">getattr01x</Attribute>
    <Ent tag="3"></Ent>
    </Entity>
    <Entity>
    <Code>11120</Code>
    <Des>镇区范围</Des>
    <EntType>LWPOLYLINE,POLYLINE</EntType>
    <LayerName>05镇区范围</LayerName>
    <ColorIndex></ColorIndex>
    <IsClose></IsClose>
    <LineType>Center</LineType>
    <LineWidth></LineWidth>
    <GlobeWidth></GlobeWidth>
    <HasHatch></HasHatch>
    <Thickness></Thickness>
    <Attribute ID="111200">getattr01x</Attribute>
    <Ent tag="3"></Ent>
    </Entity>
      

  15.   

    是不是这里的<Attribute ID="111100">getattr01x</Attribute>
      <Ent tag="3" />
    应该改成
    <Attribute ID="111100">getattr01x</Attribute>
      <Ent>3</Ent>
      

  16.   

    最好不让改哈还有就是
    Attribute 不能改