示例#1
0
        public static RateResponse FromXml(string xml)
        {
            RateResponse r    = new RateResponse();
            int          idx1 = 0;
            int          idx2 = 0;

            if (xml.Contains("<ZipOrigination>"))
            {
                idx1        = xml.IndexOf("<ZipOrigination>") + 17;
                idx2        = xml.IndexOf("</ZipOrigination>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<ZipDestination>"))
            {
                idx1        = xml.IndexOf("<ZipDestination>") + 16;
                idx2        = xml.IndexOf("</ZipDestination>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Pounds>"))
            {
                idx1        = xml.IndexOf("<Pounds>") + 8;
                idx2        = xml.IndexOf("</Pounds>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Ounces>"))
            {
                idx1        = xml.IndexOf("<Ounces>") + 8;
                idx2        = xml.IndexOf("</Ounces>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Container>"))
            {
                idx1        = xml.IndexOf("<Container>") + 11;
                idx2        = xml.IndexOf("</Container>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Size>"))
            {
                idx1        = xml.IndexOf("<Size>") + 6;
                idx2        = xml.IndexOf("</Size>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Zone>"))
            {
                idx1        = xml.IndexOf("<Zone>") + 6;
                idx2        = xml.IndexOf("</Zone>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            int lastidx = 0;

            while (xml.IndexOf("<MailService>", lastidx) > -1)
            {
                Postage p = new Postage();
                idx1          = xml.IndexOf("<MailService>", lastidx) + 13;
                idx2          = xml.IndexOf("</MailService>", lastidx + 13);
                p.MailService = xml.Substring(idx1, idx2 - idx1);

                idx1     = xml.IndexOf("<Rate>", lastidx) + 6;
                idx2     = xml.IndexOf("</Rate>", lastidx + 13);
                p.Amount = Decimal.Parse(xml.Substring(idx1, idx2 - idx1));
                r.Postage.Add(p);
                lastidx = idx2;
            }
            return(r);
        }
示例#2
0
        public static RateResponse FromXml(string xml)
        {
            RateResponse r = new RateResponse();
            int idx1 = 0;
            int idx2 = 0;

            if(xml.Contains("<ZipOrigination>"))
            {
                idx1 = xml.IndexOf("<ZipOrigination>") + 17;
                idx2 = xml.IndexOf("</ZipOrigination>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<ZipDestination>"))
            {
                idx1 = xml.IndexOf("<ZipDestination>") + 16;
                idx2 = xml.IndexOf("</ZipDestination>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Pounds>"))
            {
                idx1 = xml.IndexOf("<Pounds>") + 8;
                idx2 = xml.IndexOf("</Pounds>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Ounces>"))
            {
                idx1 = xml.IndexOf("<Ounces>") + 8;
                idx2 = xml.IndexOf("</Ounces>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Container>"))
            {
                idx1 = xml.IndexOf("<Container>") + 11;
                idx2 = xml.IndexOf("</Container>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Size>"))
            {
                idx1 = xml.IndexOf("<Size>") + 6;
                idx2 = xml.IndexOf("</Size>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            if (xml.Contains("<Zone>"))
            {
                idx1 = xml.IndexOf("<Zone>") + 6;
                idx2 = xml.IndexOf("</Zone>");
                r.OriginZip = xml.Substring(idx1, idx2 - idx1);
            }

            int lastidx = 0;
            while (xml.IndexOf("<MailService>", lastidx) > -1)
            {
                Postage p = new Postage();
                idx1 = xml.IndexOf("<MailService>", lastidx) + 13;
                idx2 = xml.IndexOf("</MailService>", lastidx + 13);
                p.MailService = xml.Substring(idx1, idx2 - idx1);

                idx1 = xml.IndexOf("<Rate>", lastidx) + 6;
                idx2 = xml.IndexOf("</Rate>", lastidx + 13);
                p.Amount = Decimal.Parse(xml.Substring(idx1, idx2 - idx1));
                r.Postage.Add(p);
                lastidx = idx2;
            }
            return r;
        }