locked
How to read the plain SOAP xml message RRS feed

  • Question

  • User1439246188 posted

    Hello all,

    I am getting below plain  response a web service .  And I wand to read the RESPONSE_DATA elements. Please help me to get that.

    <?xml version='1.0' encoding='UTF-8'?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header>
    <gwsxns:GWSXHeader xmlns:gwsxns="http://gwsxurl/">
    <gwsxns:ProviderTxnID>gadjahg</gwsxns:ProviderTxnID>
    <gwsxns:ProviderTxnStatus>hjHjh</gwsxns:ProviderTxnStatus>
    </gwsxns:GWSXHeader>
    </S:Header>
    <S:Body>
    <ns2:searchResultResponse xmlns:ns2="http://searchresult.org/">
    <return>
    <UEN_RESPONSE>
    <BODY>
    <RESPONSE_DATA>
    <ENTITY_MAIN_INFORMATION>
    <EMAIL></EMAIL>
    <ENTITY_NAME>Test</ENTITY_NAME>
    </ENTITY_MAIN_INFORMATION>
    <REG_ADDR_GROUP>
    <REG_ADDRESS_STANDARD>N</REG_ADDRESS_STANDARD>
    </REG_ADDR_GROUP>
    </RESPONSE_DATA>
    </BODY>
    </UEN_RESPONSE>
    </return>
    </ns2:searchResultResponse>
    </S:Body>
    </S:Envelope>

    Thanks,

    Nagendra

    Saturday, December 5, 2015 12:36 AM

Answers

  • User-271186128 posted

    Hi Nagendra,

    Welcome to asp.net forum.

    From your description, I suggest you could refer to the following code:

                string str = TextBox1.Text; //get the xml 
    
                //using the string.substring method to get the response_data
                int startIndex = str.IndexOf("<RESPONSE_DATA>");
                int endIndex = str.IndexOf("</RESPONSE_DATA>");
                string xmldata = str.Substring(startIndex, endIndex - startIndex + 16);
    
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmldata);
    
                //select Node
                XmlNodeList list = doc.SelectNodes("/RESPONSE_DATA//ENTITY_NAME");
                int i = list.Count;
                Response.Write(i.ToString());
    
                foreach (XmlNode item in list)
                {
    Response.Write(item.Name); Response.Write(item.InnerText); }

    Best regards,
    Dilllion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 8, 2015 5:34 AM

All replies

  • User1289604957 posted

    Hi,

    I highly recommand LinqToXML. It is simple to use :

    string xml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?>
    <soap:envelope xmlns:xsd=""w3.org/2001/XMLSchema"" xmlns:xsi=""w3.org/2001/XMLSchema-instance"" xmlns:soap=""schemas.xmlsoap.org/soap/envelope/"">;
    <soap:body>
    <order> <id>1234</id> </order>
    </soap:body>
    </soap:envelope>";


    XDocument xDoc = XDocument.Load(new StringReader(xml));
    var id = xDoc.Descendants("id").First().Value;


    To loop elements in body:

    XDocument xDoc = XDocument.Load(new StringReader(xml));
    XNamespace soap = XNamespace.Get("schemas.xmlsoap.org/soap/envelope/");

    var items = xDoc.Descendants(soap+"body").Elements();
    foreach (var item in items)
    {
    Console.WriteLine(item.Name.LocalName);
    }

    Hope that could help!

    Best,

    Maher

    Saturday, December 5, 2015 11:37 PM
  • User-271186128 posted

    Hi Nagendra,

    Welcome to asp.net forum.

    From your description, I suggest you could refer to the following code:

                string str = TextBox1.Text; //get the xml 
    
                //using the string.substring method to get the response_data
                int startIndex = str.IndexOf("<RESPONSE_DATA>");
                int endIndex = str.IndexOf("</RESPONSE_DATA>");
                string xmldata = str.Substring(startIndex, endIndex - startIndex + 16);
    
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmldata);
    
                //select Node
                XmlNodeList list = doc.SelectNodes("/RESPONSE_DATA//ENTITY_NAME");
                int i = list.Count;
                Response.Write(i.ToString());
    
                foreach (XmlNode item in list)
                {
    Response.Write(item.Name); Response.Write(item.InnerText); }

    Best regards,
    Dilllion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 8, 2015 5:34 AM