If you work with Visual Studio then it is pretty easy to get persistable settings. Right click on the project in Solution Explorer and choose Properties. Select the Settings tab and click on the hyperlink if settings doesn't exist.
Use the Settings tab to create application settings. Visual Studio creates the files Settings.settings
and Settings.Designer.settings
that contain the singleton class Settings
inherited from ApplicationSettingsBase. You can access this class from your code to read/write application settings:
Properties.Settings.Default["SomeProperty"] = "Some Value";
Properties.Settings.Default.Save(); // Saves settings in application configuration file
This technique is applicable both for console, Windows Forms, and other project types.
Note that you need to set the scope property of your settings. If you select Application scope then Settings.Default.<your property> will be read-only.
Reference: How To: Write User Settings at Run Time with C# - Microsoft Docs
OK, let's separate the question of the characters that:
- aren't valid at all in any XML document.
- need to be escaped.
The answer provided by @dolmen in "What are invalid characters in XML" is still valid but needs to be updated with the XML 1.1 specification.
1. Invalid characters
The characters described here are all the characters that are allowed to be inserted in an XML document.
1.1. In XML 1.0
The global list of allowed characters is:
[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
Basically, the control characters and characters out of the Unicode ranges are not allowed.
This means also that calling for example the character entity 
is forbidden.
1.2. In XML 1.1
The global list of allowed characters is:
[2] Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
[2a] RestrictedChar ::= [#x1-#x8] | [#xB-#xC] | [#xE-#x1F] | [#x7F-#x84] | [#x86-#x9F]
This revision of the XML recommendation has extended the allowed characters so control characters are allowed, and takes into account a new revision of the Unicode standard, but these ones are still not allowed : NUL (x00), xFFFE, xFFFF...
However, the use of control characters and undefined Unicode char is discouraged.
It can also be noticed that all parsers do not always take this into account and XML documents with control characters may be rejected.
2. Characters that need to be escaped (to obtain a well-formed document):
The <
must be escaped with a <
entity, since it is assumed to be the beginning of a tag.
The &
must be escaped with a &
entity, since it is assumed to be the beginning a entity reference
The >
should be escaped with >
entity. It is not mandatory -- it depends on the context -- but it is strongly advised to escape it.
The '
should be escaped with a '
entity -- mandatory in attributes defined within single quotes but it is strongly advised to always escape it.
The "
should be escaped with a "
entity -- mandatory in attributes defined within double quotes but it is strongly advised to always escape it.
Best Answer
The above XML snippet is perfectly valid, as long as you've saved the XML with the correct character encoding. The default encoding for XML, if you don't specify a different one in the
<?xml
declaration, is UTF-8.If you have saved the file containing
<Ürün>
in a different encoding to UTF-8 — presumably Windows code page 1254 Turkish — it will not parse as UTF-8, so either add a<?xml version="1.0" encoding="windows-1254"?>
declaration or, much better and more portable, simply save it as UTF-8 instead. Use ‘Save as’ in your text editor and pick out that encoding.(If your text editor does not afford you that option, or it insists on re-loading UTF-8 files in code page 1254, get a better text editor.)