本文介绍了数据集到webservice中的所需格式XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是网络服务开发的新手,目前我们的网络服务将从商店退回商品库存。我们有30个商店,它将返回30倍的结果作为单个项目的数据集。目前的格式如下



stocklevel diffgr:id =StockLevel562msdata:roworder =561xmlns:msdata =#unknownxmlns:diffgr = #unknown



recordid 4672 / recordid



条码5606578926114 /条码

$ / b
stocklevel 2 / stocklevel



storecode StoreA / storecode



lastupdated 2013-02-04T10:07:36 + 00:00 / lastupdated



/ stocklevel

现在我需要修改这个功能,所以它应该在一次通话中从所有30家商店退回库存,因此需要的格式如下:

Hi,

I'm new to web service development, Currently we have web service that will return the stock of item from stores. We have 30 stores and it will return 30 times the result as dataset for a single item. The current format is as follows

stocklevel diffgr:id="StockLevel562" msdata:roworder="561" xmlns:msdata="#unknown" xmlns:diffgr="#unknown"

recordid 4672 /recordid

barcode 5606578926114 /barcode

stocklevel 2 /stocklevel

storecode StoreA /storecode

lastupdated 2013-02-04T10:07:36+00:00 /lastupdated

/stocklevel
Now i need to modify the function, so that it should return the stock from all 30 stores in a single call, so format needed is just like below:

stocklevel
            barcode 5606578926114 /barcode
stocklevel storecode=""StoreA"" lastupdated=""2013-02-04T10:07:36+00:00"" 2 /stocklevel
stocklevel storecode=""StoreB"" lastupdated=""2013-02-04T10:07:36+00:00"" 10 /stocklevel
stocklevel storecode=""StoreC"" lastupdated=""2013-02-04T10:07:36+00:00"" 6 /stocklevel

…etc…

/stocklevel





我不知道是否可以通过格式化数据集或XML来实现。所以任何帮助都会很棒...



在此先感谢....





Anish



I don't know whether it can be achieved by formatting the dataset or XML. So any help would be great...

Thanks in Advance....


Anish

推荐答案

string XMLName = FilePath + "Code_Proj.xml";
            using (FileStream fs = new FileStream(XMLName, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write("<?xml version='1.0' encoding='UTF-8'?> \n" +
                             "<stocklevel>\n ");

                    DataView dv = new DataView(ds.Tables[0]);
                    System.Data.DataTable dt = dv.ToTable(true, "Barcode");

                    foreach (DataRow drv in dt.Rows)
                    {
                        string Barcode = drv["Barcode"].ToString();

                        DataRow[] drs = ds.Tables[0].Select("Barcode = '" + Barcode + "'");
                        sw.Write("<barcode>" + Barcode + "\n");
                        sw.Write("</barcode>\n");
                        foreach (DataRow drData in drs)
                        {
                            string Storecode = drData["storecode"].ToString();
                            string LastUpdatedDate = drData["lastupdated"].ToString();
                            string Level = drData["stocklevel"].ToString();
                            sw.Write("<stocklevel storecode='" + Storecode + "' lastupdated='" + LastUpdatedDate + "' " + Level + " /> \n");
                        }
                    }
                    sw.Write("</stocklevel>\n");
                    fs.Flush();
                }
            }

            GC.Collect();


这篇关于数据集到webservice中的所需格式XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:25