要在 ~/App_Data/  下面先建立一個 logXMLFile.xml 檔~~才能在其他的aspx使用。

 

Dim path As String = HttpContext.Current.Request.MapPath("~/App_Data/")

        '載入xml檔案
        Dim xml As XElement = XElement.Load((path & "logXMLFile.xml"))

        'LINQ 查詢XML
        '--------注意一定要指定資料型態,要不然不能轉換。
        Dim emps = From x In xml.Elements() _
                   Select New With { _
                   .name = CType(x.Element("name"), String), _
                    .sex = CType(x.Element("sex"), String), _
                    .height = CType(x.Element("height"), Integer), _
                    .weight = CType(x.Element("weight"), Integer), _
                    .country = CType(x.Element("country"), String) _
                    }

        GridView1.DataSource = emps
        GridView1.DataBind()

 

PS:我裡面是人事資料如,name,sex,height,weight,country。

 


我的xml是

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href='mystyle.css' title='pro' rype='text/css'?>
<models>
  <model>
    <name>Kevin</name>
    <sex>Male</sex>
    <height>190</height>
    <weight>72</weight>
    <country>usa</country>
    <phone>0933154286</phone>
  </model>
  <model>
    <name>Cindy</name>
    <sex>Female</sex>
    <height>180</height>
    <weight>72</weight>
    <country>France</country>
    <phone>0945133456</phone>
   </model>
  <model>
    <name>Clare</name>
    <sex>Female</sex>
    <height>170</height>
    <weight>65</weight>
    <country>USA</country>
    <phone>0955283283</phone>
  </model>
</models>

arrow
arrow
    全站熱搜

    毛魚 發表在 痞客邦 留言(0) 人氣()