/// Read data to DataSet through the ReadXml function by passing in a specific XML string.
Protected static DataSet GetDataSetByXml (string xmlData)
{
Try {DataSet ds = new DataSet ();
Using (StringReader xmlSR = new StringReader (xmlData ))
{
Ds. ReadXml (xmlSR, XmlReadMode. InferTypedSchema); // ignore any inline architecture, deduce a strong schema from the data and load the data. If it cannot be inferred, it is interpreted as string data.
If (ds. Tables. Count> 0)
{
Return ds;
}
}
Return null;
}
Catch (Exception)
{
Return null;
}
}
/// The formatted xml file is automatically read and converted to DataSet by the input Xml file path (including the file name.
Public static DataSet GetDataSetByXmlpath (string strXmlPath)
{
Try
{
DataSet ds = new DataSet ();
// Read XML to DataSet
StreamReader sr = new StreamReader (strXmlPath, Encoding. Default );
Ds. ReadXml (sr );
Sr. Close ();
If (ds. Tables. Count> 0)
Return ds;
Return null;
}
Catch (Exception)
{
Return null;
}
}