<?xml version="1.0" encoding="gb2312"?>
<products>
  <product>
    <name>CPU</name>
    <price>600</price>
    <company>Intel</company>
  </product>
  <product>
    <name>显卡</name>
    <price>300</price>
    <company>gj</company>
  </product>
</products>怎么按<name>把<product></product>的内容读出并转为字符串,急

解决方案 »

  1.   

    System.Data.DataTable.ReadXml 方法
      

  2.   

    System.Xml.XmlDocument x = new System.Xml.XmlDocument();
    x.Load(Server.MapPath("A.xml"));
    System.Xml.XmlNodeList nodes = x.SelectNodes("//Name");
    foreach(System.Xml.XmlNode y in nodes)
    {
    if(y.InnerText.IndexOf("") >-1)
    Response.Write(y.InnerText);
    }System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.Load("A.xml");
    foreach (System.Xml.XmlNode n in doc.DocumentElement.SelectNodes("product[contains(Name,'')]"))
    {
     MessageBox.Show(n.InnerXml);
    }
    或用LINQ查询
    参考
      

  3.   

    楼上的,那怎么把他转成字节流呢,我想把他在服务端用socket传出去,顺便问下客户端怎么接受并显示