Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I am returning a xml string which is showing in below format.

XML1:
<CustomerOrder><Version>1.0</Version><Id /><MessageCreateDate>2010-08-09T18:06:19.561+05:30</MessageCreateDate><MessageCreateBy>OCI</MessageCreateBy><MessageGUID>2bf8c699-2118-49bc-8574-ca54f4d3d14f</MessageGUID><MessagePurpose>ProcessSalesOrderEBM</MessagePurpose><CustomerContext><CustomerNumber>350590463</CustomerNumber><BusinessUnitId>4545</BusinessUnitId><Buid>350</Buid><IBU>350</IBU><Country>KR</Country><Language 


But i want in formatted xml like as shown below

XML2:
<pre lang="xml">- <CustomerOrder>
  <Version>1.0</Version>
  <Id />  <MessageCreateDate>2010-08-09T18:06:19.561+05:30</MessageCreateDate>
  <MessageCreateBy>OCI</MessageCreateBy>
  <MessageGUID>2bf8c699-2118-49bc-8574-ca54f4d3d14f</MessageGUID>
  <MessagePurpose>ProcessSalesOrderEBM</MessagePurpose>
- <CustomerContext>
  <CustomerNumber>350590463</CustomerNumber>
  <BusinessUnitId>4545</BusinessUnitId>
  <Buid>350</Buid>




please find the below code which i am using
 StringBuilder sb = new StringBuilder();
                    // used on each read operation
                    byte[] buf = new byte[8192];
                    // prepare the web page we will be asking for
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(OFS_DataURL + in_message_id);
                    request.Credentials = CredentialCache.DefaultCredentials;

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    //response.ContentType = "text/xml";                   
                    
                    // we will read data via the response stream
                    using (Stream resStream = response.GetResponseStream())
                    {

                        string tempString = null;
                        int count = 0;

                        do
                        {
                            // fill the buffer with data
                            count = resStream.Read(buf, 0, buf.Length);
                            if (count != 0)
                            {
                                tempString = Encoding.UTF8.GetString(buf, 0,count);
                                sb.Append(tempString);
                            }
                        }
                        while (count > 0); // any more data to read?
                        resStream.Close();                    }
                    

                    Response = Serialize<String>(sb.ToString());
                    Response = DeSerialize<String>(Response);
return Response;


so it is returning xml as a string as shown in XML1 but i wnat xml to be return in XML2 foramt.

can anybody please help how to do this?
Posted

1 solution

The second XML you are showing is Indented XML
so you need to create XMLWriter object and write xml with XMLSetting as "INDENT"

check following link, will help you
Check it[^]
 
Share this answer
 

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