Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. My xml file is displayed as a long string. How do I insert newlines?

My xml file is displayed as a long string. How do I insert newlines?

Scheduled Pinned Locked Moved XML / XSL
questioncsharpxml
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lnong
    wrote on last edited by
    #1

    I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line. How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I? Do I use functions from the XmlWhitespace class or something??

    Richard DeemingR 1 Reply Last reply
    0
    • L lnong

      I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line. How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I? Do I use functions from the XmlWhitespace class or something??

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You need to pass an XmlWriter to the Save method:

      void SaveXml(XmlDocument doc, Stream s, Encoding encoding)
      {
      XmlTextWriter xtw = new XmlTextWriter(s, encoding);
      xtw.Formatting = Formatting.Indented;
      xtw.Indentation = 1;
      xtw.IndentChar = '\t';

      doc.Save(xtw);
      

      }


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups