不是说dataSet是存储表结构的吗,xml的树形结点结构读取到dataSet中之后会是怎么样的呢

解决方案 »

  1.   

    读取xml到dataset中,同样是表结构
      

  2.   

    那xml通常会有多层结构。如果是一层就直接对应表结构了啊。多层怎么解释呢?
      

  3.   

         /// <summary>
            /// 获取XML数据库中的数据的方法
            /// </summary>
            /// <param name="strFilePath">传入文件路径</param>
            /// <returns>返回一个数据集</returns>
            public static DataSet GetAllDataFromXML(string strFilePath)
            {
                DataSet ds = new DataSet();
                FileInfo fileInfo = new FileInfo(strFilePath);
                if (fileInfo.Exists)
                {
                    try
                    {
                        ds.ReadXml(strFilePath);
                    }
                    catch { }
                }
                else
                {
                    ds = null;
                }
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count < 1)
                        ds = null;
                }
                return ds;
            }自己试一试就知道了
      

  4.   

    楼上那段是dataset读取xml的代码,如果xml是简单结构没问题,如果如下,是读取不了的- <purchaseorder>
    - <header>
      <code>ptcgdd001</code> 
      <date>2002-08-02</date> 
      <vendorcode>002</vendorcode> 
      <deptcode>0801</deptcode> 
      <personcode>080102</personcode> 
      <purchase_type_code>1</purchase_type_code> 
      <operation_type_code>普通采购</operation_type_code> 
      <address /> 
      <recsend_type>02</recsend_type> 
      <currency_name>人民币</currency_name> 
      </header>
    - <body>
    - <entry>
      <inventorycode>0001</inventorycode> 
      <checkflag>0</checkflag> 
      <unitcode>11001</unitcode> 
      <quantity>500</quantity> 
      <num>500</num> 
      <quotedprice>0</quotedprice> 
      <price>10</price> 
      <taxprice>11.7</taxprice> 
      <money>5000</money> 
      <tax>850</tax> 
      <sum>5850</sum> 
      <discount>0</discount> 
      <natprice>10</natprice> 
      <natmoney>5000</natmoney> 
      <assistantunit>11001</assistantunit> 
      <nattax>850</nattax> 
      <natsum>5850</natsum> 
      <natdiscount>0</natdiscount> 
      <taxrate>17</taxrate> 
      </entry>
    - <entry>
      <inventorycode>0004</inventorycode> 
      <checkflag>0</checkflag> 
      <unitcode>11001</unitcode> 
      <quantity>1000</quantity> 
      <num>1000</num> 
      <quotedprice>0</quotedprice> 
      <price>11.9658</price> 
      <taxprice>14</taxprice> 
      <money>11965.81</money> 
      <tax>2034.19</tax> 
      <sum>14000</sum> 
      <discount>0</discount> 
      <natprice>11.9658</natprice> 
      <natmoney>11965.81</natmoney> 
      <assistantunit>11001</assistantunit> 
      <nattax>2034.19</nattax> 
      <natsum>14000</natsum> 
      <natdiscount>0</natdiscount> 
      <taxrate>17</taxrate> 
       </entry>
      </body>
      </purchaseorder>
      

  5.   

    楼主是想问复杂xml如何读取吧
      

  6.   

    嗯,好像现在知道一点,就是数据读到DATASET中以后,如果数据有关系,或者包含,有多张表就得用数据验证文件XSD文件读取。好像里面还有些什么,这个XSD有点复杂啊