DataStoreDataExtensions.ImportXml(this IDataStoreBase dataStore, string text) Method
.NET Standard 2.x
Inserts data from an XML string into the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int ImportXml(this IDataStoreBase dataStore, string text);
Parameters
text
System.String
A string specifying the XML data.
The XML string must comply with the plain-format XML or DataWindow XML.
Returns
System.Int32
Returns the number of rows that were imported if it succeeds.
Remarks
For plain-format XML: It imports the XML data to the primary buffer.
For DataWindow XML: It imports data from all of the buffers from the XML string to the corresponding buffers and, if any, imports the data for DataWindowChild
.
Examples
The following code example demonstrates how to import the department records from an XML string to a DataStore.
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ImportXmlExample
{
private readonly SchoolContext _context;
public ImportXmlExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
// Instantiates the datastore with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
// Gets the XML string to be imported.
string importXml = GetImportXml();
// Imports the XML to datastore.
datastore.ImportXml(importXml);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("DepartmentID: {0}; Name: {1}; Budget: {2}",
datastore.GetItem<int>(row, "departmentid"),
datastore.GetItem<string>(row, "name"),
datastore.GetItem<decimal>(row, "budget"));
}
/*This code produces the following output:
Rowcount: 2
DepartmentID: 1; Name: Engineering; Budget: 220000.0000
DepartmentID: 2; Name: English; Budget: 120000.0000
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x