这种XML如何转成 datatable

?xml version="1.0" encoding="utf-8" standalone="yes"?>






























<exam programcode="GB"
examcode="G191C"
resourcefilename=""
resourceversion=""
name="GB0191 - 构建中小企业网络V7.0"
examformname="G191CF1"
driverversion=""
startdatetime="2020-06-12T13:26:37.287"
enddatetime="2020-06-12T14:13:00"

duration="2808619" restartcount="0" count="50" countcorrect="44" countincorrect="6" countskipped="0" countmarked="0" functioncode="" workstationname="">

用JAVA来做的可以先解析XML转成对象后就成表格了,JS也可以把XML解析后成表格

https://www.cnblogs.com/lilin/archive/2010/04/18/1714927.html

上面的方法其实就是解析XML文件

下面的方法更简单 你也可以试试
https://www.cnblogs.com/TechnologyDictionary/p/11445379.html

//str 是xml字符串
public static DataTable GetResultXMLToDataTable    (string str,string Dt_Name)
{
    DataSet xmlDs = new DataSet("ds");
    StringReader stream = null;
    XmlTextReader reader = null;
    try
    {
        using (stream = new StringReader(str))
        {
            using (reader = new XmlTextReader(stream))
            {
                xmlDs.ReadXml(reader);
                return xmlDs.Tables[Dt_Name];
            }
        }
    }
    catch (Exception ex)
    {
       //Get Exception
    }
    finally
    {
        if (reader != null)
            reader.Close();
        if (stream != null)
            stream.Close();
    }
    return null;
}