Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my request xml. I need to convert to XElement in C#.

HTML
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.bit.com" xmlns:ter="http://tp.requests.objects.webservice.cc.bit.com">
   <soapenv:header>
      <web:authenticationtoken>
         <web:key>rgg3
         <web:password>testenv
         <web:user>test@gmail.com
      
   
   <soapenv:body>
      <web:getsbyzip>
         <web:getsbyzipcoderequest>
            <ter:arraygetbyzipcode>
               <!--Zero or more repetitions:-->
               <ter:getbyzipcode>
                  <ter:servicelevel>KK
                  <ter:servicewing>Takal
               
                <ter:getbyzipcode>
                  <ter:servicelevel>KK
                  <ter:servicewing>Takal


What I have tried:

C#
public XElement GetRequestXml(GetModel getModel)
        {
            XNamespace web = "http://webservices.bit.com";
            XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
            XNamespace ter = "http://tp.requests.objects.webservice.cc.bit.com";
            XElement requestXml = new XElement(soapenv + "Envelope",
                new XElement(soapenv + "Header",
               new XElement(web + "AuthenticationToken",
               new XAttribute(web + "key", "rgg3"),
               new XAttribute(web + "password", "testenv"),
                new XAttribute(web + "user", "test@gmail.com"))),

                new XElement(soapenv + "Body",
                 new XElement(web + "GetByZioCode",
                new XElement(web + "GetByZipCodeRequest",
                new XElement(ter + "arrayTerminalByZipCode",
               new XElement(ter + "TerminalByZipCode",
               new XAttribute(ter + "serviceLevel", getModel.serviceLevel),
			   new XAttribute(ter + "servicewing", getModel.servicewing)              
               new XElement(ter + "TerminalByZipCode",
               new XAttribute(ter + "serviceLevel", getModel.serviceLevel),
			   new XAttribute(ter + "servicewing", getModel.servicewing),
           
              ))));

            return requestXml;
        }


I tried above code. if any help. Thanks in Advance.
Posted
Updated 30-Mar-19 22:43pm
v2
Comments
Patrice T 31-Mar-19 0:08am    
what is the question/problem.
Richard Deeming 4-Apr-19 14:03pm    
Your sample XML is invalid. Some of the names in your C# code don't match the names in the sample XML. And your C# code is using attributes where your sample XML has elements.

1 solution

 
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