ASP.NET 3.5 bind to XML string

With ASP.NET 3.5 I can easily bind to an XML file by using an XmlDataSource.

How can I bind to an XML string instead of a file?

Answers


Use the XmlDataSource.Data property.

XmlDataSource dataSource    = new XmlDataSource();
dataSource.Data             = "<root><element>Item #1</element><element>Item #2</element></root>";
dataSource.XPath            = "root/element";
dataSource.DataBind();

Alternately, you could specify the data declaratively:

<asp:xmldatasource 
  id="XmlDataSource1" 
  runat="server" 
>
  <data>
    <Books>
      <LanguageBooks>
        <Book Title="Pure JavaScript" Author="Wyke, Gilliam, and Ting"/>
        <Book Title="Effective C++ Second Edition" Author="Scott Meyers"/>
        <Book Title="Assembly Language Step-By-Step" Author="Jeff Duntemann"/>
        <Book Title="Oracle PL/SQL" Author="Steven Feuerstein"/>
      </LanguageBooks>

      <SecurityBooks>
        <Book Title="Counter Hack" Author="Ed Skoudis"/>
      </SecurityBooks>

    </Books>
  </data>
</asp:xmldatasource>

From the XmlDataSource docs here:

XML data can also be stored directly by the data source control in string form using the Data property.


Need Your Help

PDO PHP MYSQL SESSION

php mysql session pdo

I have been working on it and I can't make it work.

Bad results with a simple FFT 1D OpenCL example

opencl gpu fft amd-processor

I try to do a simple FFT 1D with clAmdFft OpenCL libray. For this, I am using a cosinus signal with a frequency equal to 10 Hz and a sampling frequency of sizex*frequency_signal with sizex the numb...