用.net的XMLNode可以读取节点,但是对于下面这种attribute该怎么读呢? <user id="03">
   <from>"MC"</from>
   <to>"EA"</to>
   <attribute name="aa" length="10" datamap="aamap" />
   <attribute name="bb" length="11" datamap="bbmap" istrue = "false"/>
</user>
其中attribute的数量可以是任意条

解决方案 »

  1.   

    XmlNodeList NodeList = xmldoc.DocumentElement.ChildNodes;
    for(int i = 0;i<NodeList.Count;i++)
    {
    XmlNode Node = NodeList[i];
    if (i == index)
    {
    //加载根结点的树
    //判断是否为子树的依据是根据xsd架构文件的属性确定的,
    //含有子树的结点(元素)是包含属性的,这个不是通用的xml解析程序
    TreeNode bootNode = null;
    if (Node.Attributes.Count >0) 
    {
                            foreach(XmlAttribute att in Node.Attributes)
    {
    bootNode= new TreeNode(att.InnerXml,5,5);
    tv.Nodes.Add(bootNode);
    }
    }
    if (bootNode!=null)
    LoadTree(bootNode,Node);
    break;
    }
    }
      

  2.   

    doc.selectnodes(user/attribute)就是所有的attribute节点不知道你要读attribute节点还是其中的属性得到节点后随你干什么
      

  3.   

    参考(读取XML文档并绑定到datagrid控件)
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Data" %><html>
     
    <script language="C#" runat="server">    protected void Page_Load(Object Src, EventArgs E) {
            DataSet ds = new DataSet();        FileStream fs = new FileStream(Server.MapPath("myXml.xml"),FileMode.Open,FileAccess.Read); //myXml.xml是要读取的xml文档
            StreamReader reader = new StreamReader(fs);
            ds.ReadXml(reader);
            fs.Close();        DataView Source = new DataView(ds.Tables[0]);        MyLiteral.Text = Source.Table.TableName;
            MyDataGrid.DataSource = Source;
            MyDataGrid.DataBind();
        }</script><body>  <h3><font face="宋体">表的 XML 数据:<asp:Literal id="MyLiteral" runat="server" /></font></h3>  <ASP:DataGrid id="MyDataGrid" runat="server"
        Width="900"
        BackColor="#ccccff"
        BorderColor="black"
        ShowFooter="false"
        CellPadding=3
        CellSpacing="0"
        Font-Name="宋体"
        Font-Size="9pt"
        HeaderStyle-BackColor="#aaaadd"
        EnableViewState="false"
      /></body>
    </html>
      

  4.   

    读节点还是属性?实在PC机上读还是在PDA中读?
      

  5.   

    两种方法:XmlDocument xmldoc = new XmlDocument();
    xmldoc.LoadXml("<user ...</user>");第一种:
    foreach(XmlNode node in xmldoc.DocumentElement.ChildNodes)
    {
         if(node.Name == "attribute")
         {
             //这里的 node 就是你想要的东东
         }
    }第二种:foreach(XmlNode node in doc.selectnodes("/user/attribute"))
    {
          //这里的 node 就是你想要的东东
    }
      

  6.   

    我得到了attribute这个node,但是对于其中的属性,怎么取值?
      

  7.   

    node.Attributes[n]
    or
    node.Attributes["Name"]