刚学XML,随便乱写的//item[starts-with(title,"test")]

解决方案 »

  1.   

    DataSet ds=new DataSet();
    ds.ReadXml(Server.MapPath("XX.xml"));
    DataGrid dg=new DataGrid();
    dg.DataSource=ds;
    dg.DataBind();
    这样应该可以。
      

  2.   

    #region 检索XML文件
    public static string search(string keyword,wordNode node)
    {
    XmlDocument doc = new XmlDocument();
    doc.Load("Dict.xml");
    XmlElement root = doc.DocumentElement;
    string xpath = "//Dictionary/dictItem[keyword='" + keyword + "']"; 
    XmlNodeList nodes = root.SelectNodes(xpath);
    if(nodes.Count == 1)
    {
    switch(node)
    {
    case wordNode.keyword :
    return nodes[0].ChildNodes[0].InnerText;
    //break;
    case wordNode.describe:
    return nodes[0].ChildNodes[1].InnerText;
    //break;
    case wordNode.kind:
    return nodes[0].ChildNodes[2].InnerText;
    //break;
    case wordNode.referrence:
    return nodes[0].ChildNodes[3].InnerText;
    //break;
    case wordNode.all:
    string txt = "";
    foreach(XmlNode nod in nodes[0].ChildNodes)
    {
    txt += nod.InnerText;
    }
    return txt;
    //break;
    default:
    return "参数不正确";
    //break;
    }
    }
    else
    {
    return "对不起,没找到!";
    }
    }
    #endregion