Парсинг xml. XmlException was unhandled Invalid character in the given encoding - C#
Формулировка задачи:
Товарищи, здравствуйте. Встала задача распарсить xmlку. Руководствуясь msdn'ом написал код, однако после запуска дебага студия выдает такую ошибку: XmlException was unhandled Invalid character in the given encoding. Line 5, position 1. В чем может быть проблема?
Код C#:
Код xml документа:
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string path = "source.xml";
- XmlTextReader xmlReader = new XmlTextReader(path);
- while (xmlReader.Read()) {
- switch (xmlReader.NodeType){
- case XmlNodeType.Element:
- Console.Write("<" + xmlReader.Name);
- Console.Write(">");
- break;
- case XmlNodeType.Text:
- Console.WriteLine(xmlReader.Value);
- break;
- case XmlNodeType.EndElement:
- Console.Write("</" + xmlReader.Name);
- Console.Write(">");
- break;
- }
- }
- Console.ReadLine();
- }
- }
- }
Листинг программы
- <?xml version='1.0' ?>
- <source>
- <configuration>
- <filesource>
- /temp/Files/
- </filesource>
- <period>
- 30
- </period>
- <message>
- Вам пришел новый документ
- </message>
- </configuration>
- </source>
Решение задачи: «Парсинг xml. XmlException was unhandled Invalid character in the given encoding»
textual
Листинг программы
- <?xml version='1.0' encoding="UTF-8" ?>
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д