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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to write >, <, &to XML file

how to write >, <, &to XML file

Scheduled Pinned Locked Moved C#
questionxmltutorial
4 Posts 2 Posters 0 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.
  • D Offline
    D Offline
    donkaiser
    wrote on last edited by
    #1

    Hello, I try to write these characters to an XML file. but in the XML file it shows: > < & instead. how can i write correctly to the XML file or at least read correctly(assign the innertext to a variable)? here is my code for writing to XML file: XmlElement title= xmldoc.CreateElement("Title"); title.InnerText = txtName.Text; newBook.AppendChild(title); Donkaiser

    D 2 Replies Last reply
    0
    • D donkaiser

      Hello, I try to write these characters to an XML file. but in the XML file it shows: > < & instead. how can i write correctly to the XML file or at least read correctly(assign the innertext to a variable)? here is my code for writing to XML file: XmlElement title= xmldoc.CreateElement("Title"); title.InnerText = txtName.Text; newBook.AppendChild(title); Donkaiser

      D Offline
      D Offline
      donkaiser
      wrote on last edited by
      #2

      haha but in the XML file it shows: & gt; & lt; & amp; instead. So confusing!!! Donkaiser

      R 1 Reply Last reply
      0
      • D donkaiser

        haha but in the XML file it shows: & gt; & lt; & amp; instead. So confusing!!! Donkaiser

        R Offline
        R Offline
        Robin Panther
        wrote on last edited by
        #3

        there are some characters that has special meaning in html/xml files, for example <, >, & and so on. So, if you need to display such character in xml/html file you should use one of the special form of symbol writing, for example '&' followed by character short form and followed by ';'. '&' gt ';' for 'greater' sign. When you are reading html/xml file you have to decode such symbols. In your case, if you have only this three symbols in your file - you can make simple replace, either through string.replace(), either through regex.replace(). But if you can get more symbols (probably, all special chars) - then use standart functions - parse xml file into set of xml element object (or any other way) and read it's InnerText property. Notice, that if you'll write special chars into InnerText, and read it from it - It'll be ok. XmlDocument doc = new XmlDocument(); doc.LoadXml("" + "some textmore text" + ""); XmlElement elem = (XmlElement)doc.DocumentElement.FirstChild; elem.InnerText = "testing < > &"; MessageBox.Show(elem.InnerText); MessageBox shows "testing < > &" ____________________________________________ Robin Panther http://www.robinland.com

        1 Reply Last reply
        0
        • D donkaiser

          Hello, I try to write these characters to an XML file. but in the XML file it shows: > < & instead. how can i write correctly to the XML file or at least read correctly(assign the innertext to a variable)? here is my code for writing to XML file: XmlElement title= xmldoc.CreateElement("Title"); title.InnerText = txtName.Text; newBook.AppendChild(title); Donkaiser

          D Offline
          D Offline
          donkaiser
          wrote on last edited by
          #4

          Using innerText format automatically the text. Donkaiser

          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