asp.net<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<html>
<head> <B>Reading XML</B> </head>
<script language="VB" runat="server">
  Sub Page_Load(Source As Object, E As EventArgs) 
    Dim ds          As New DataSet
    Dim fs          As filestream
    dim xmLStream   As StreamReader
    fs = New filestream(Server.MapPath("test.xml"), FileMode.Open, FileAccess.Read)
    xmlStream = new StreamReader(fs)
    ds.ReadXML(XmlStream)
    DataGrid1.DataSource=ds.Tables("factlist").DefaultView
    DataGrid1.DataBind()
  End Sub
</script>
<form runat=server>
 <asp:DataGrid id="DataGrid1" runat="server" /> 
</form>
</body>
</html>

解决方案 »

  1.   

    DECLARE @idoc int
    DECLARE @doc varchar(1000)
    --sample XML document
    SET @doc ='
    <root>
      <Customer cid= "C1" name="Janine" city="Issaquah">
          <Order oid="O1" date="1/20/1996" amount="3.5" />
          <Order oid="O2" date="4/30/1997" amount="13.4">Customer was very satisfied
          </Order>
       </Customer>
       <Customer cid="C2" name="Ursula" city="Oelde" >
          <Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue 
                 white red">
                <Urgency>Important</Urgency>
                Happy Customer.
          </Order>
          <Order oid="O4" date="1/20/1996" amount="10000"/>
       </Customer>
    </root>
    'set @doc='<fact>
    <factlist>
    <fact_no>K0</fact_no>
    <fact_nm>總公司</fact_nm>
    </factlist>
    <factlist>
    <fact_no>K1</fact_no>
    <fact_nm>總公司</fact_nm>
    </factlist>
    <factlist>
    <fact_no>K2</fact_no>
    <fact_nm>總公司</fact_nm>
    </factlist>
     </fact>'
    -- Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc-- Execute a SELECT statement using OPENXML rowset provider.
    SELECT *
    FROM OPENXML (@idoc, '/fact/factlist', 2)
          WITH (fact_no    char(2) , 
                fact_nm nvarchar(100) )
    EXEC sp_xml_removedocument @idoc