Click here to Skip to main content
15,894,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
HTML
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


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
Posted
Updated 3-May-13 5:00am
v5
Comments
CHill60 3-May-13 10:24am    
You will need to post the code that produces the dataset
Kenneth Haugland 3-May-13 10:32am    
Dont Dataset have a ToXML function?

1 solution

Hi Anish,

Try the below code which may be helpful for u . :)

C#
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();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900