You must Sign In to post a response.
  • Category: XML

    How to remove white space in xml page

    i have one xml file that file by default getting some white space from page starting to xml tags.

    like from pagestarting to <xml version="">

    inside the parent to child tag white space i was handle but out side of the space is i cant any one tell me how can i do this....asap.

    Thnak u for your quick responce...
  • #741022

    Use preserveWhitespace "False" for this.


    XmlDocument doc = new XmlDocument();
    doc.preserveWhitespace = false;
    // doc.InnerXml contains no spaces or returns


  • #769680
    try to use below line of code after placing xml string into XmlText variable.

    xmlText = Regex.Replace(
    xmlText, @"(?=<[^=]+?>)(?=</?\w+\s+\w+)(<.*?)(\s+)(.*?>)",@"$1_$3",
    RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

    The above regular expression only used to remove whitespaces within the < and > nodes but not other areas like comments

    B.Ramana Reddy

  • Sign In to post your comments