Xml Reader

Posted on 2013-09-26
Medium Priority
Last Modified: 2013-10-16
I wanted a general Idea on what the code does below, I assume its parsing xml data from an xml file into a database. What do these methods do and why not just use an xml reader to read data instead create these extra ones...



namespace R_and_M_XMLReader
    using Cust;
    using Items;
    using SaleOrd;

    class Program
        public void ReadfromXML()
            if (!Directory.Exists(@"E:\Old_R&M_XML_files"))

            if (Directory.Exists(@"E:\R&M_XML files"))
                Item_Service itm_svc = new Item_Service();
                itm_svc.UseDefaultCredentials = true;
                itm_svc.Url = @"http://absvii.abs.com:7087/DynamicsNAVRnM/WS/R%20&%20%20M/Page/Item";

                DirectoryInfo Item_di = new DirectoryInfo(@"E:\R&M_XML files");
                FileInfo[] Item_files = Item_di.GetFiles(@"*.xml");
                foreach (FileInfo file in Item_files)
                    StreamReader Item_sr = new StreamReader(file.DirectoryName + @"\" + file.Name);
                    XmlDocument ItemXML = new XmlDocument();
                    Item itm;
                    XmlNodeList nodelist = ItemXML.SelectNodes("/Items/item");
                    foreach (XmlNode node in nodelist)
                        string itmnum = String.Empty;
                            itm = new Item();
                            itm.No = node["itemNumber"].InnerText;
                            itmnum = itm.No;
                            itm_svc.Create(ref itm);
                            itm.Item_Category_Code = node["productGroup"].InnerText;
                            itm.Product_Group_Code = node["productGroup2"].InnerText;
                            itm.Description = node["articleDescription"].ChildNodes[1].InnerText.Substring(0,30);
                            itm.Business_Product_Group = node["kernelProductGroup"].InnerText;
                            itm.Units_per_Parcel = decimal.Parse(node["packingUnit"].InnerText);
                            itm.Excise_Prod_Posting_Group = node["customsTariffNumber"].InnerText;
                            itm.Country_Region_of_Origin_Code = node["itemProductionCountry"].InnerText;
                            itm.Net_Weight = decimal.Parse(node["netWeight"].InnerText);
                            itm.Minimum_Order_Quantity = decimal.Parse(node["minimumOrderQuantity"].InnerText);
                            itm.Reordering_Policy = Reordering_Policy.Lot_for_Lot;
                            itm.Large_Description = node["articleDescription"].ChildNodes[1].InnerText;
                            itm_svc.Update(ref itm);
                            Console.WriteLine("Item Created Successfully");
                        catch (Exception ex)
            #region not used

            //if (Directory.Exists(@"E:\R&M_XML files\Order"))
            //    DirectoryInfo Ord_di = new DirectoryInfo(@"E:\R&M_XML files\Order");
            //    FileInfo[] Ord_files = Ord_di.GetFiles(@"*.xml");
            //    foreach (FileInfo file in Ord_files)
            //    {
            //        //string OrderXMLstring = String.Empty;
            //        //using (XmlTextReader OrderXMLReader = new XmlTextReader(file.DirectoryName + @"\" + file.Name))
            //        //{
            //        //    SalesOrder_Service SO_service = new SalesOrder_Service();
            //        //    SO_service.UseDefaultCredentials = true;
            //        //    SO_service.Url = @"http://absvii.abs.com:7087/DynamicsNAVRnM/WS/R%20&%20%20M/Page/SalesOrder";
            //        //    while (OrderXMLReader.Read())
            //        //    {
            //        //        switch (OrderXMLReader.NodeType)
            //        //        {
            //        //            case XmlNodeType.Element: // The node is an element.
            //        //                OrderXMLstring += "<" + OrderXMLReader.Name + ">";
            //        //                break;
            //        //            case XmlNodeType.Text: //Display the text in each element.
            //        //                OrderXMLstring += OrderXMLReader.Value;
            //        //                break;
            //        //            case XmlNodeType.EndElement: //Display the end of the element.
            //        //                OrderXMLstring += "</" + OrderXMLReader.Name + ">";
            //        //                break;
            //        //        }
            //        //    }
            //        //}
            //        //file.MoveTo(@"E:\Old_R&M_XML_files\" + file.Name);
            //        StreamReader Ord_sr = new StreamReader(file.DirectoryName + @"\" + file.Name);
            //        XmlDocument OrdXML = new XmlDocument();
            //        OrdXML.LoadXml(Ord_sr.ReadToEnd());
            //        Ord_sr.Close();
            //    }

        static void Main(string[] args)
            Program pg = new Program();

Open in new window

Question by:Moizsaif123
  • 2
LVL 52

Accepted Solution

Carl Tawn earned 2000 total points
ID: 39527054
They are using a StreamReader because the XmlDocument LoadXml() method requires a string of XML, it cannot read a file directly.

I assume they are using an XmlDocument and XmlNodeList because they are only interested in a subset of the nodes in the document, and this way is simpler than using an XmlReader.

But generally, it is loading an XmlDocument, grabbing each "item" node that is a child of the "Items" node, loading each one into a custom object and then passing it to some sort of service tier to process.

Author Comment

ID: 39576086
Following the Second document "BUILD ON CLIENT SIDE" on how to publish a webservice using .NET and Navision i have followed all the step but am receiving a compile time error

I am receiving a sguigly line under "Business_Product_Group", posted a screenshot for that..I dont know if you have any idea on this or not..

Author Comment

ID: 39576471
Ignore the last comment, my question is will this finally dump all the data into a database or what kind of transaction will it do..

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question