C#使用Queue将多个参数传递给XML

时间:2015-04-13 13:21:12

标签: c# xml list for-loop parameters

我有一个从Oracle CRM OnDemand获取数据的Web服务。我想创建另一个WS,它接受给定客户记录的字段,并将这些字段作为参数传递给XML编写器,然后创建XML以传递给另一个Web服务(由另一个团队开发)。

我可以创建XML并传递参数。但是,我只测试3-4个字段并传递它们。我需要传递超过4个参数,我知道这是一个非常差的编程来创建一个需要3个以上参数的函数。 (编辑)我创建了一个从页面接收参数的队列,我只传递队列。我想将数据字段出列,后跟一串我要传递到XML页面的字符串。

这就是我现在所拥有的。

...for (int intIndx = 0; intIndx < intCount; intIndx++)
                    {
                        //Create queue to store all the data obtained from a given Account
                        Queue<string> q = new Queue<string>();
                        //Easier to reference 
                        var acctName=  objAcctQryOut.ListOfAccount[intIndx].AccountName;
                        var acctWebsite = objAcctQryOut.ListOfAccount[intIndx].WebSite;
                        q.Enqueue(acctName);                            
                        addyInsert.CountryCode = objAcctQryOut.ListOfAccount[intIndx].PrimaryBillToCountry;
                        q.Enqueue(addyInsert.CountryCode);
                        addyInsert.Line1 = objAcctQryOut.ListOfAccount[intIndx].PrimaryBillToStreetAddress;
                        q.Enqueue(addyInsert.Line1);
                        addyInsert.Line2 = accountInfo.PrimaryBillToStreetAddress2;
                        q.Enqueue(addyInsert.Line2);
                        addyInsert.Line3 = accountInfo.PrimaryBillToStreetAddress3;
                        q.Enqueue(addyInsert.Line3);
                        addyInsert.City = objAcctQryOut.ListOfAccount[intIndx].PrimaryBillToCity;
                        q.Enqueue(addyInsert.City);
                        addyInsert.CountyCodeVertex = accountInfo.PrimaryBillToCounty;
                        q.Enqueue(addyInsert.CountyCodeVertex);
                        addyInsert.StateProvinceCodeVertex = accountInfo.PrimaryBillToState;
                        q.Enqueue(addyInsert.StateProvinceCodeVertex);even know? 
                        custResponse.CustomerNumber = accountInfo.FuriganaName;
                        q.Enqueue(custResponse.CustomerNumber);
                        custInput.BillingCurrency = accountInfo.CurrencyCode;
                        q.Enqueue(custInput.BillingCurrency);
                        custInput.Email = accountInfo.CustomText1;
                        q.Enqueue(custInput.Email);
                        custInput.TravelPortCustomerTypeCode = accountInfo.AccountType;
                        q.Enqueue(custInput.TravelPortCustomerTypeCode);
                        var count = q.Count;

                        var xml = new XML();
                        xml.sendAccountInfoXML(q);
                        //xml.sendAccountInfoXML(acctName, addyInsert.CountryCode, addyInsert.Line1, addyInsert.Line2, addyInsert.Line3, acctWebsite);

                    }

private void createXML(Queue<string> q)
        {
            string saveLoc = @"C:\Users\XML Test\test{0}.xml";
            XmlTextWriter writer = new XmlTextWriter(saveLoc, System.Text.Encoding.UTF8);
            XmlDocument doc = new XmlDocument();
            writer.WriteStartDocument(true);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("HEADER");
            createNode(q, writer);
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
            doc.Save(writer);
        }
private void createNode(Queue<string> q, XmlWriter writer)
        {
            Queue<string> x = new Queue<string>();
            x.Enqueue("ACCOUNTNAME");
            x.Enqueue("BILLINGCOUNTRY");
            x.Enqueue("BILLINGLINE1");
            x.Enqueue("BILLINGLINE2");
            x.Enqueue("BILLINGLINE3");
            x.Enqueue("BILLINGCITY");
            x.Enqueue("BILLINGCOUNTY");
            x.Enqueue("BILLINGSTATE");
            x.Enqueue("CUSTOMERNUMBER");
            x.Enqueue("BILLINGCURRENCY");
            x.Enqueue("CUSTOMEREMAIL");
            x.Enqueue("CUSTOMERTYPE");
            //x.Enqueue("CUSTOMURL");
            writer.WriteStartElement("ACCOUNTINFO");
            for (int i = 0; i < x.Count; i++)
            {
                writer.WriteStartElement(x.Dequeue());
                for (int j = 0; j < q.Count; j++)
                {
                    writer.WriteString(q.Dequeue());
                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();
        }

但是,我觉得嵌套循环没有正常运行。你介意试着引导我通过它并指出我搞砸了吗?谢谢。

0 个答案:

没有答案