예제 #1
0
        private TestOrderTotal GetTestOrderTotal(XmlReader reader)
        {
            if (reader == null)
            {
                throw new Exception("reader");
            }

            while (reader.NodeType != XmlNodeType.Element)
            {
                reader.Read();
            }

            if (reader.LocalName != "TestOrderTotal")
            {
                throw new XmlException("Unexpected xml tag " + reader.LocalName);
            }

            reader.Read();

            while (reader.NodeType == XmlNodeType.Whitespace)
            {
                reader.Read();
            }

            TestOrderTotal testOrderTotal = new TestOrderTotal();

            while (reader.LocalName != "TestOrderTotal")
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    case "OrderID":
                        testOrderTotal.OrderID = reader.ReadElementContentAsString();
                        break;

                    case "Subtotal":
                        testOrderTotal.Subtotal = reader.ReadElementContentAsString();
                        break;

                    case "Freight":
                        testOrderTotal.Freight = reader.ReadElementContentAsString();
                        break;

                    case "Total":
                        testOrderTotal.Total = reader.ReadElementContentAsString();
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                    if ((reader.LocalName == "TestOrderTotal") && reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
            return(testOrderTotal);
        }
예제 #2
0
        private MailMergeDataTable GetTestOrderTotals(int TestOrderId)
        {
            List <TestOrderTotal> orders = new List <TestOrderTotal>();
            FileStream            fs     = new FileStream(@"wwwroot/data/docio/order-totals.xml", FileMode.Open, FileAccess.Read);
            XmlReader             reader = XmlReader.Create(fs);

            if (reader == null)
            {
                throw new Exception("reader");
            }

            while (reader.NodeType != XmlNodeType.Element)
            {
                reader.Read();
            }

            if (reader.LocalName != "TestOrderTotals")
            {
                throw new XmlException("Unexpected xml tag " + reader.LocalName);
            }

            reader.Read();

            while (reader.NodeType == XmlNodeType.Whitespace)
            {
                reader.Read();
            }

            while (reader.LocalName != "TestOrderTotals")
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    case "TestOrderTotal":
                        TestOrderTotal testOrder = GetTestOrderTotal(reader);
                        if (testOrder.OrderID == TestOrderId.ToString())
                        {
                            orders.Add(testOrder);
                            break;
                        }
                        break;
                    }
                    reader.Read();
                }
                else
                {
                    reader.Read();
                    if ((reader.LocalName == "TestOrderTotals") && reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }

            MailMergeDataTable dataTable = new MailMergeDataTable("OrderTotals", orders);

            reader.Dispose();
            fs.Dispose();
            return(dataTable);
        }