-2

Below is the sample code for creation of xml.

var bpsResponseXml = new XElement("BPSResponse");         

bpsResponseXml.Add(new XElement("Response",
                                    new XElement("Code", "804"),
                                    new XElement("Text", "TagID value is not genuine")));

var outPutXml = bpsResponseXml.Value;

Current Output xml is shown below, as you can see there are spaces between the characters and words :

<BPSResponse>    <Response>      <Code>804</Code>      <Text>TagID value is not genuine.</Text>    </Response>  </BPSResponse>

Rather than above xml i want trimmed xml as below :

<BPSResponse><Response><Code>804</Code><Text>TagID value is not genuine.</Text></Response></BPSResponse>

Please help for the same!

PrinceT
  • 459
  • 4
  • 19
  • Possible duplicate [Efficient way to remove ALL whitespace from String?](http://stackoverflow.com/questions/6219454/efficient-way-to-remove-all-whitespace-from-string) – Izzy Dec 01 '14 at 09:35
  • No, its not. Because, it also trims attribute value as well. i want TagID value is not genuine as output. your suggession gives me TagIDvalueisnotgenuine. as output. – PrinceT Dec 01 '14 at 09:40
  • 2
    You haven't shown how you're getting the XML out - just using the `Value` property will only give you the text content anyway. If you're using `Save`, you can just specify `SaveOptions.DisableFormatting`. – Jon Skeet Dec 01 '14 at 09:40
  • var outPutXml = bpsResponseXml.ToString(); – PrinceT Dec 01 '14 at 09:41
  • 2
    You're probably looking for this [ToString](http://msdn.microsoft.com/library/bb551415.aspx) overload, which takes a [SaveOptions](http://msdn.microsoft.com/library/system.xml.linq.saveoptions.aspx) parameter. In your case `DisableFormatting`. – Corak Dec 01 '14 at 09:42
  • 2
    @Corak: Nice - I hadn't spotted there's an overload of `ToString` for that as well as `Save`... – Jon Skeet Dec 01 '14 at 09:45

1 Answers1

1

Below is Sample code which will resolve issue.

var bpsResponseXml = new XElement("BPSResponse");         

bpsResponseXml.Add(new XElement("Response",
                                    new XElement("Code", "804"),
                                    new XElement("Text", "TagID value is not genuine")));

var outPutXml = bpsResponseXml.ToString(System.Xml.Linq.SaveOptions.DisableFormatting);
PrinceT
  • 459
  • 4
  • 19